/* ============================================================================
   Brute Info — css/layout.css
   The site chrome: sticky blurred header (brand, primary nav, search, theme
   toggle, cart badge, auth zone / avatar dropdown), the mobile drawer, and the
   multi-column legal footer.

   ALL of the markup styled here is generated by js/layout.js. Page agents never
   author header or footer markup — they only provide the two mount points:
       <div id="site-header"></div> … <div id="site-footer"></div>
   ========================================================================== */

/* --------------------------------------------------------------------------
   MOUNT POINTS — reserve the exact final height so nothing shifts while JS
   boots. #site-header is the sticky element itself once mounted.
   -------------------------------------------------------------------------- */
#site-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  display: block;
  min-height: var(--header-h);
}
#site-footer { display: block; }

/* ==========================================================================
   HEADER
   ========================================================================== */
.site-header {
  height: var(--header-h);
  background: var(--surface-overlay);
  -webkit-backdrop-filter: saturate(180%) blur(var(--glass-blur));
  backdrop-filter: saturate(180%) blur(var(--glass-blur));
  border-bottom: 1px solid transparent;
  transition: border-color var(--dur-base) var(--ease-standard),
              box-shadow var(--dur-base) var(--ease-standard),
              background-color var(--dur-base) var(--ease-standard);
}
/* js/layout.js adds .is-scrolled once the page scrolls past 8px */
.site-header.is-scrolled {
  border-bottom-color: var(--border);
  box-shadow: var(--shadow-sm);
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .site-header { background: var(--surface); }
}

.header-inner {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  height: 100%;
}

/* --- Brand -------------------------------------------------------------- */
.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--text);
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  font-weight: var(--fw-extrabold);
  letter-spacing: var(--tracking-tighter);
  text-decoration: none;
  flex: 0 0 auto;
  border-radius: var(--radius-sm);
}
.brand:hover { color: var(--text); text-decoration: none; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 2.125rem;
  height: 2.125rem;
  flex: 0 0 auto;
  transition: transform var(--dur-base) var(--ease-spring);
}
.brand:hover .brand-mark { transform: rotate(-6deg) scale(1.06); }
.brand-mark svg { width: 100%; height: 100%; }
.brand-text { white-space: nowrap; }
.brand-accent { color: var(--primary); }

/* --- Primary nav -------------------------------------------------------- */
.nav-main {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex: 1 1 auto;
}
.nav-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-tight);
  text-decoration: none;
  white-space: nowrap;
  transition: color var(--dur-fast) var(--ease-standard),
              background-color var(--dur-fast) var(--ease-standard);
}
.nav-link:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.nav-link:active { background: var(--surface-3); }
.nav-link.is-active { color: var(--primary); }
.nav-link.is-active::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 0.05rem;
  width: 1.1rem;
  height: 2px;
  border-radius: var(--radius-full);
  background: var(--primary);
  transform: translateX(-50%);
}

/* --- Right side --------------------------------------------------------- */
.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: 0 0 auto;
  margin-left: auto;
}

/* Shared square icon button used by search / theme / cart / hamburger */
.icon-btn {
  position: relative;
  display: grid;
  place-items: center;
  width: 2.375rem;
  height: 2.375rem;
  flex: 0 0 auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  text-decoration: none;
  transition: color var(--dur-fast) var(--ease-standard),
              border-color var(--dur-fast) var(--ease-standard),
              background-color var(--dur-fast) var(--ease-standard);
}
.icon-btn > svg { width: 1.15rem; height: 1.15rem; }
.icon-btn:hover {
  color: var(--primary);
  border-color: var(--primary-border);
  background: var(--primary-soft);
  text-decoration: none;
}
.icon-btn:active { background: var(--primary-soft-hover); }
.icon-btn:focus-visible { outline: 2px solid var(--focus-ring-color); outline-offset: 2px; }

/* --- Search affordance -------------------------------------------------- */
.header-search {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  height: 2.375rem;
  min-width: 13rem;
  padding: 0 var(--space-2) 0 var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-subtle);
  font-size: var(--fs-md);
  text-decoration: none;
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease-standard),
              background-color var(--dur-fast) var(--ease-standard),
              color var(--dur-fast) var(--ease-standard);
}
.header-search:hover {
  border-color: var(--primary-border);
  background: var(--surface);
  color: var(--text-muted);
  text-decoration: none;
}
.header-search:focus-visible { outline: 2px solid var(--focus-ring-color); outline-offset: 2px; }
.header-search > svg { width: 1rem; height: 1rem; flex: 0 0 auto; }
.header-search-text { flex: 1; text-align: left; white-space: nowrap; }
.header-search .kbd { margin-left: auto; }

/* --- Cart --------------------------------------------------------------- */
.cart-btn { overflow: visible; }
.cart-count {
  position: absolute;
  top: -0.3rem;
  right: -0.3rem;
  min-width: 1.05rem;
  height: 1.05rem;
  padding-inline: 0.25rem;
  display: grid;
  place-items: center;
  border-radius: var(--radius-full);
  background: var(--danger);
  color: #fff;
  font-size: var(--fs-2xs);
  font-weight: var(--fw-bold);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  box-shadow: 0 0 0 2px var(--surface);
  animation: bi-badge-pop var(--dur-base) var(--ease-spring);
}
.cart-count[hidden] { display: none; }
@keyframes bi-badge-pop {
  from { transform: scale(0.5); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}
.cart-btn.is-filled { color: var(--primary); border-color: var(--primary-border); }

/* --- Theme toggle ------------------------------------------------------- */
.theme-toggle { overflow: hidden; }
.theme-toggle svg {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 1.15rem;
  height: 1.15rem;
  transition: transform var(--dur-base) var(--ease-spring),
              opacity var(--dur-fast) var(--ease-standard);
}
.theme-toggle .icon-sun { opacity: 1; transform: none; }
.theme-toggle .icon-moon { opacity: 0; transform: rotate(-70deg) scale(0.5); }
:root[data-theme="dark"] .theme-toggle .icon-sun { opacity: 0; transform: rotate(70deg) scale(0.5); }
:root[data-theme="dark"] .theme-toggle .icon-moon { opacity: 1; transform: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { opacity: 0; transform: rotate(70deg) scale(0.5); }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { opacity: 1; transform: none; }
}

/* --- Auth zone ---------------------------------------------------------- */
.auth-zone { display: flex; align-items: center; gap: var(--space-2); }
.auth-zone .btn { --btn-h: 2.375rem; }

/* Placeholder occupying the exact final width while auth state resolves —
   this is what keeps the header at zero layout shift. */
.auth-pending {
  width: 11.75rem;
  height: 2.375rem;
  border-radius: var(--radius-md);
  background: var(--skeleton-base);
  flex: 0 0 auto;
}

/* --- Avatar dropdown ---------------------------------------------------- */
.user-menu { position: relative; }
.user-menu-trigger {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  height: 2.375rem;
  padding: 0.2rem 0.55rem 0.2rem 0.2rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease-standard),
              background-color var(--dur-fast) var(--ease-standard);
}
.user-menu-trigger:hover { border-color: var(--primary-border); background: var(--surface-2); }
.user-menu-trigger:focus-visible { outline: 2px solid var(--focus-ring-color); outline-offset: 2px; }
.user-menu-trigger[aria-expanded="true"] { border-color: var(--primary-border); background: var(--surface-2); }
.user-menu-trigger .avatar { width: 1.875rem; height: 1.875rem; font-size: var(--fs-xs); }
.user-menu-name {
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  max-width: 8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-menu-caret {
  width: 0.9rem; height: 0.9rem;
  color: var(--text-subtle);
  transition: transform var(--dur-base) var(--ease-out);
}
.user-menu-trigger[aria-expanded="true"] .user-menu-caret { transform: rotate(180deg); }

.user-dropdown {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  z-index: var(--z-dropdown);
  min-width: 16rem;
  padding: var(--space-2);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-xl);
  opacity: 0;
  transform: translateY(-6px) scale(0.98);
  transform-origin: top right;
  transition: opacity var(--dur-fast) var(--ease-standard),
              transform var(--dur-fast) var(--ease-out);
}
.user-dropdown[hidden] { display: none; }
.user-dropdown.is-open { opacity: 1; transform: none; }

.user-dropdown-head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: var(--space-2);
}
.user-dropdown-id { min-width: 0; display: flex; flex-direction: column; }
.user-dropdown-name { font-size: var(--fs-md); font-weight: var(--fw-bold); color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-dropdown-email { font-size: var(--fs-sm); color: var(--text-subtle); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* .menu-item / .menu-sep / .menu-label are defined in components.css */

/* --- Hamburger ---------------------------------------------------------- */
.nav-toggle { display: none; }
.nav-toggle-bars, .nav-toggle-bars::before, .nav-toggle-bars::after {
  display: block;
  width: 1.05rem;
  height: 2px;
  border-radius: var(--radius-full);
  background: currentColor;
  transition: transform var(--dur-base) var(--ease-out),
              opacity var(--dur-fast) var(--ease-standard);
}
.nav-toggle-bars { position: relative; }
.nav-toggle-bars::before { content: ""; position: absolute; top: -6px; }
.nav-toggle-bars::after { content: ""; position: absolute; top: 6px; }
.nav-toggle[aria-expanded="true"] .nav-toggle-bars { background: transparent; }
.nav-toggle[aria-expanded="true"] .nav-toggle-bars::before { transform: translateY(6px) rotate(45deg); }
.nav-toggle[aria-expanded="true"] .nav-toggle-bars::after { transform: translateY(-6px) rotate(-45deg); }

/* ==========================================================================
   MOBILE DRAWER
   ========================================================================== */
.drawer-scrim {
  position: fixed;
  inset: 0;
  z-index: calc(var(--z-drawer) - 1);
  background: var(--overlay-scrim);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity var(--dur-base) var(--ease-standard);
}
.drawer-scrim[hidden] { display: none; }
.drawer-scrim.is-open { opacity: 1; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: var(--z-drawer);
  width: min(21rem, 88vw);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  padding: var(--space-5);
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-xl);
  overflow-y: auto;
  overscroll-behavior: contain;
  transform: translateX(100%);
  transition: transform var(--dur-slow) var(--ease-out);
}
.drawer[hidden] { display: none; }
.drawer.is-open { transform: none; }

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}
.drawer-close {
  display: grid;
  place-items: center;
  width: 2.25rem; height: 2.25rem;
  border: 0;
  border-radius: var(--radius-md);
  background: none;
  color: var(--text-muted);
  cursor: pointer;
}
.drawer-close:hover { background: var(--surface-2); color: var(--text); }
.drawer-close svg { width: 1.25rem; height: 1.25rem; }

.drawer-nav { display: flex; flex-direction: column; gap: var(--space-1); }
.drawer-section-title {
  padding: var(--space-3) var(--space-4) var(--space-1);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-bold);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  color: var(--text-subtle);
}
.drawer-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
  text-decoration: none;
  transition: background-color var(--dur-fast) var(--ease-standard),
              color var(--dur-fast) var(--ease-standard);
}
.drawer-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.drawer-link:active { background: var(--surface-3); }
.drawer-link.is-active { background: var(--primary-soft); color: var(--primary-soft-text); }
.drawer-link > svg { width: 1.15rem; height: 1.15rem; flex: 0 0 auto; opacity: 0.85; }
.drawer-link-tail {
  margin-left: auto;
  min-width: 1.25rem;
  height: 1.25rem;
  padding-inline: 0.3rem;
  display: grid;
  place-items: center;
  border-radius: var(--radius-full);
  background: var(--danger);
  color: #fff;
  font-size: var(--fs-2xs);
  font-weight: var(--fw-bold);
}

.drawer-actions { display: flex; flex-direction: column; gap: var(--space-3); margin-top: auto; }
.drawer-user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.drawer-user-id { min-width: 0; display: flex; flex-direction: column; }
.drawer-user-name { font-size: var(--fs-md); font-weight: var(--fw-bold); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-user-email { font-size: var(--fs-sm); color: var(--text-subtle); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ==========================================================================
   RESPONSIVE HEADER
   ========================================================================== */
@media (max-width: 1180px) {
  .header-search-text, .header-search .kbd { display: none; }
  .header-search { min-width: 0; width: 2.375rem; padding: 0; justify-content: center; }
}
@media (max-width: 960px) {
  .nav-main { display: none; }
  .nav-toggle { display: grid; }
  .user-menu-name, .user-menu-caret { display: none; }
  .user-menu-trigger { padding: 0.2rem; }
  .auth-zone .btn-ghost { display: none; }
  .auth-pending { width: 6.75rem; }
}
@media (max-width: 640px) {
  :root { --header-h: var(--header-h-compact); }
  .brand-text { display: none; }
  .header-search { display: none; }
  .header-inner { gap: var(--space-3); }
}
@media (min-width: 961px) {
  .drawer, .drawer-scrim { display: none !important; }
}

/* ==========================================================================
   FOOTER
   ========================================================================== */
.site-footer {
  margin-top: var(--space-20);
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: var(--fs-md);
}
.footer-top {
  display: grid;
  grid-template-columns: minmax(18rem, 1.5fr) repeat(4, minmax(0, 1fr));
  gap: var(--space-10) var(--space-8);
  padding-block: var(--space-14) var(--space-10);
}

.footer-brand { display: flex; flex-direction: column; gap: var(--space-4); max-width: 36ch; }
.footer-brand .brand { font-size: var(--fs-xl); }
.footer-blurb { line-height: var(--lh-relaxed); color: var(--text-muted); }

.footer-entity {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  font-size: var(--fs-sm);
  line-height: 1.6;
  color: var(--text-subtle);
  font-style: normal;
}
.footer-entity-name { font-weight: var(--fw-bold); color: var(--text); font-size: var(--fs-md); }

.footer-contact { display: flex; flex-direction: column; gap: var(--space-2); font-size: var(--fs-sm); }
.footer-contact-row { display: flex; align-items: flex-start; gap: var(--space-2); color: var(--text-muted); }
.footer-contact-row > svg { width: 1rem; height: 1rem; margin-top: 0.15rem; flex: 0 0 auto; color: var(--text-subtle); }
.footer-contact-row a { color: var(--text-muted); text-decoration: none; }
.footer-contact-row a:hover { color: var(--primary); text-decoration: underline; }
.footer-emails { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-3); }

.footer-social { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.footer-social a {
  display: grid;
  place-items: center;
  width: 2.125rem;
  height: 2.125rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  transition: color var(--dur-fast) var(--ease-standard),
              border-color var(--dur-fast) var(--ease-standard),
              background-color var(--dur-fast) var(--ease-standard),
              transform var(--dur-fast) var(--ease-out);
}
.footer-social a > svg { width: 1.05rem; height: 1.05rem; }
.footer-social a:hover {
  color: var(--primary);
  border-color: var(--primary-border);
  background: var(--primary-soft);
  transform: translateY(-2px);
}
.footer-social a:focus-visible { outline: 2px solid var(--focus-ring-color); outline-offset: 2px; }

.footer-col { display: flex; flex-direction: column; gap: var(--space-3); }
.footer-col-title {
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  color: var(--text);
}
.footer-col ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.footer-link {
  color: var(--text-muted);
  text-decoration: none;
  width: fit-content;
  transition: color var(--dur-fast) var(--ease-standard);
}
.footer-link:hover { color: var(--primary); text-decoration: none; }
.footer-link:focus-visible { outline: 2px solid var(--focus-ring-color); outline-offset: 2px; }

.footer-legal {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-4);
  padding-block: var(--space-5);
  border-top: 1px solid var(--border-subtle);
  font-size: var(--fs-sm);
  color: var(--text-subtle);
}
.footer-legal-links { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-5); list-style: none; margin: 0; padding: 0; }

.footer-ids {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-6);
  padding-bottom: var(--space-5);
  font-size: var(--fs-xs);
  color: var(--text-subtle);
  font-family: var(--font-mono);
}
.footer-ids dt { display: inline; font-weight: var(--fw-bold); letter-spacing: var(--tracking-wide); }
.footer-ids dd { display: inline; margin: 0 0 0 var(--space-2); }
.footer-ids > div { display: flex; align-items: baseline; }

.footer-note {
  padding-bottom: var(--space-8);
  font-size: var(--fs-xs);
  color: var(--text-subtle);
  line-height: 1.6;
  max-width: 90ch;
}

@media (max-width: 1080px) {
  .footer-top { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .footer-brand { grid-column: 1 / -1; max-width: 60ch; }
}
@media (max-width: 760px) {
  .footer-top { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-8); }
}
@media (max-width: 460px) {
  .footer-top { grid-template-columns: minmax(0, 1fr); }
  .footer-legal { flex-direction: column; align-items: flex-start; }
}

/* ==========================================================================
   PAGE SHELL HELPERS (used by every page stylesheet)
   ========================================================================== */
.page-head {
  padding-block: var(--space-10) var(--space-8);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.page-head-inner { display: flex; flex-direction: column; gap: var(--space-4); }
.page-head-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-5);
}
.page-title { font-size: var(--fs-4xl); }
.page-sub { color: var(--text-muted); font-size: var(--fs-lg); max-width: 60ch; }
.page-actions { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-3); }

/* Centred single-column shell used by the auth pages and 404 */
.shell-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100svh - var(--header-h));
  padding-block: var(--space-12);
}

/* Two-column app shell: content + a sticky summary rail (cart, checkout, course) */
.shell-aside {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 22rem;
  gap: var(--space-8);
  align-items: start;
}
.shell-aside-rail {
  position: sticky;
  top: calc(var(--header-h) + var(--space-6));
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
@media (max-width: 960px) {
  .shell-aside { grid-template-columns: minmax(0, 1fr); }
  .shell-aside-rail { position: static; }
}
