/* SEF Studio: persistent chrome (topnav, container, footer, flashes).
 * Lives on every page. Companion to surfaces.css which holds per-page rules.
 */

/* Topnav: thin oxblood top rule, cream background, mono uppercase for the
 * tenant pill and meta links. The tenant pill carries a 2px underline in the
 * tenant's brand-primary colour (or oxblood when no BrandKit is set).
 */
.topnav {
  background: var(--color-bg);
  border-top: 2px solid var(--color-oxblood);
  border-bottom: 1px solid var(--color-rule);
  position: relative;
  z-index: 5;
}
.topnav-inner {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  height: 64px;
  max-width: var(--canvas-max);
  margin: 0 auto;
  padding-inline: var(--gutter);
}
.topnav .brand {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 1.1rem;
  letter-spacing: -0.01em;
  color: var(--color-oxblood);
  text-decoration: none;
}
.topnav .brand:hover { color: var(--color-oxblood-hover); }
/* Brand text is full on desktop, short ('Studio') on mobile so it never
 * wraps and competes with the pill + hamburger for the row. */
.topnav .brand .brand-short { display: none; }
.topnav .spacer { flex: 1; }

.topnav .topnav-link,
.topnav .topnav-user {
  font-family: var(--font-mono);
  font-size: var(--type-eyebrow);
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--color-muted);
  text-decoration: none;
  white-space: nowrap;
}
.topnav .topnav-link:hover { color: var(--color-oxblood); }
.topnav .topnav-user { color: var(--color-text); }

.topnav .inline { margin: 0; display: inline; }

/* Tenant pill: small mono badge with the brand-primary underline.
 * Also acts as the tenant switcher — clicking it goes to /tenants/.
 * The ⇄ glyph hints at "switch" without taking up a separate nav slot. */
.tenant-pill {
  font-family: var(--font-mono);
  font-size: var(--type-eyebrow);
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--color-text);
  background: transparent;
  padding: 0 0 4px;
  border: 0;
  border-bottom: 2px solid var(--brand-primary, var(--color-oxblood));
  border-radius: 0;
  text-decoration: none;
  display: inline-flex;
  align-items: baseline;
  gap: 0.4em;
  transition: color 0.15s ease;
  white-space: nowrap;
  flex-shrink: 0;
}
.tenant-pill:hover,
.tenant-pill:focus-visible {
  color: var(--color-oxblood);
  outline: none;
}
.tenant-pill .tenant-pill-switch {
  font-size: 0.85em;
  color: var(--color-muted);
  font-weight: 400;
}
.tenant-pill:hover .tenant-pill-switch,
.tenant-pill:focus-visible .tenant-pill-switch { color: var(--color-oxblood); }

/* SEF platform switcher: <details>-based dropdown rooted on the brand
 * in the top-left. Summary is styled identically to the old plain
 * brand link so the topnav doesn't shift; the small ▾ caret is the
 * only visible hint that the brand is now expandable. Click on the
 * brand opens the panel; the panel lists every SEF platform from
 * `sef_services`, with the current one marked. Works on touch via
 * native <details> behaviour — no JS. Replaces the old .sibling-pill
 * approach. */
.brand-switcher {
  position: relative;
  flex-shrink: 0;
}
.brand-switcher > summary {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
  align-items: baseline;
  gap: 0.35em;
}
.brand-switcher > summary::-webkit-details-marker { display: none; }
.brand-switcher > summary::marker { content: ""; }
.brand-switcher > summary:focus-visible {
  outline: 2px solid var(--brand-primary, var(--color-oxblood));
  outline-offset: 4px;
}
.brand-switcher-caret {
  font-size: 0.7em;
  color: var(--color-muted);
  transition: transform 0.15s ease;
}
.brand-switcher[open] .brand-switcher-caret {
  transform: rotate(180deg);
  color: var(--color-oxblood);
}
.brand-switcher-panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 240px;
  background: var(--color-bg, #fff);
  border: 1px solid var(--color-rule, rgba(0, 0, 0, 0.12));
  border-radius: 4px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
  padding: 6px 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
}
.brand-switcher-link {
  display: flex;
  align-items: center;
  gap: 0.6em;
  padding: 10px 16px;
  text-decoration: none;
  color: var(--color-text);
  font-family: var(--font-mono);
  font-size: var(--type-eyebrow);
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  min-height: 44px;
  box-sizing: border-box;
}
.brand-switcher-link:hover,
.brand-switcher-link:focus-visible {
  background: var(--color-surface-2, rgba(0, 0, 0, 0.04));
  color: var(--color-oxblood);
  outline: none;
}
.brand-switcher-link--current {
  color: var(--color-oxblood);
  cursor: default;
}
.brand-switcher-mark {
  font-size: 0.7em;
  color: var(--color-muted);
  width: 1em;
  text-align: center;
}
.brand-switcher-link--current .brand-switcher-mark {
  color: var(--color-oxblood);
}
@media (max-width: 720px) {
  .brand-switcher-panel { min-width: 200px; }
}

/* Desktop links group: holds Home / Queue / Generate / Brief / Config /
 * user / sign-out on wide viewports. Hidden below 720px in favour of
 * the burger menu. */
.topnav .topnav-links {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

/* Burger menu: <details>-based, hidden on desktop. */
.topnav-menu {
  display: none;
  position: relative;
  flex-shrink: 0;
}
.topnav-burger {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
  flex-direction: column;
  justify-content: space-between;
  width: 20px;
  height: 14px;
  padding: 0;
  margin: 0;
  border: 0;
  outline: none;
  background: transparent;
  box-sizing: border-box;
  line-height: 0;
  -webkit-appearance: none;
          appearance: none;
  -webkit-tap-highlight-color: transparent;
}
.topnav-burger::-webkit-details-marker { display: none; }
.topnav-burger::marker { content: ""; }
.topnav-burger:focus-visible { outline: 2px solid var(--color-oxblood); outline-offset: 4px; border-radius: 2px; }
.topnav-burger-bar {
  display: block;
  width: 100%;
  height: 2px;
  background: var(--color-text);
  border-radius: 1px;
  transition: transform 0.18s ease, opacity 0.18s ease;
  transform-origin: center;
}
.topnav-menu[open] .topnav-burger-bar:nth-child(1) {
  transform: translateY(6px) rotate(45deg);
}
.topnav-menu[open] .topnav-burger-bar:nth-child(2) {
  opacity: 0;
}
.topnav-menu[open] .topnav-burger-bar:nth-child(3) {
  transform: translateY(-6px) rotate(-45deg);
}
.topnav-menu-panel {
  position: absolute;
  top: calc(100% + 1px);
  right: 0;
  min-width: 240px;
  background: var(--color-bg);
  border: 1px solid var(--color-rule);
  border-top: 2px solid var(--color-oxblood);
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
  z-index: 10;
}
.topnav-menu-link {
  font-family: var(--font-mono);
  font-size: var(--type-eyebrow);
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--color-muted);
  text-decoration: none;
}
.topnav-menu-link:hover,
.topnav-menu-link:focus-visible { color: var(--color-oxblood); outline: none; }
.topnav-menu-link.as-button {
  background: transparent;
  border: 0;
  padding: 0;
  text-align: left;
  cursor: pointer;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
}
.topnav-menu-rule {
  border: 0;
  border-top: 1px solid var(--color-rule);
  margin: 0.25rem 0;
  width: 100%;
}
.topnav-menu-user {
  font-family: var(--font-mono);
  font-size: var(--type-eyebrow);
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--color-text);
}
.topnav-menu-form { margin: 0; }

/* Desktop "More ▾" dropdown — folds the admin-rare links (Brief / Team /
 * Platforms / Sources / Config) so the topnav doesn't overflow on
 * narrower desktop windows. Hidden on mobile where the bottom tab bar
 * + More sheet handle navigation. */
.topnav-more {
  position: relative;
  flex-shrink: 0;
}
.topnav-more-summary {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  -webkit-tap-highlight-color: transparent;
}
.topnav-more-summary::-webkit-details-marker { display: none; }
.topnav-more-summary::marker { content: ""; }
.topnav-more-caret {
  font-size: 0.75em;
  transition: transform 0.18s ease;
  display: inline-block;
}
.topnav-more[open] .topnav-more-caret {
  transform: rotate(180deg);
}
.topnav-more-panel {
  position: absolute;
  top: calc(100% + 1px);
  right: 0;
  min-width: 220px;
  background: var(--color-bg);
  border: 1px solid var(--color-rule);
  border-top: 2px solid var(--color-oxblood);
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
  z-index: 10;
}

/* Mobile: hide the desktop link group, show the burger. Brand + pill
 * stay visible at all sizes so the tenant switcher is always one tap
 * away. The brand collapses to 'Studio' so it doesn't wrap. */
@media (max-width: 720px) {
  .topnav-inner { height: 56px; gap: 0.85rem; }
  .topnav .topnav-links { display: none; }
  .topnav-menu { display: inline-flex; align-items: center; }
  .topnav .brand .brand-full { display: none; }
  .topnav .brand .brand-short { display: inline; }
}

/* Main container. Existing class on <main>, narrower than the canvas. */
.container {
  width: 100%;
  max-width: var(--container-max);
  margin: 2.5rem auto 4rem;
  padding-inline: var(--gutter);
}

/* Flash messages (Django messages framework). */
.flashes {
  list-style: none;
  padding: 0;
  margin: 0 0 1.5rem;
  display: grid;
  gap: 0.5rem;
}
.flash {
  padding: 0.7rem 1rem;
  border: 1px solid var(--color-rule);
  background: var(--color-bg-tint);
  font-size: var(--type-small);
}
.flash-success { border-left: 3px solid var(--color-status-ok-fg); }
.flash-warning { border-left: 3px solid var(--color-status-warn-fg); }
.flash-error,
.flash-danger  { border-left: 3px solid var(--color-error); }
.flash-info    { border-left: 3px solid var(--color-muted); }

/* Footer: small mono colophon with a 2px oxblood top rule. */
.studio-foot {
  border-top: 2px solid var(--color-oxblood);
  background: var(--color-bg);
  margin-top: 4rem;
}
.studio-foot-inner {
  max-width: var(--canvas-max);
  margin: 0 auto;
  padding: 1.25rem var(--gutter);
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
  font-family: var(--font-mono);
  font-size: var(--type-eyebrow);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--color-muted);
}
.studio-foot-mark {
  color: var(--color-oxblood);
  font-weight: 500;
}
.studio-foot-meta { color: var(--color-muted); }
.studio-foot-spacer { flex: 1; }
.studio-foot-link {
  color: var(--color-muted);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color var(--transition-fast), color var(--transition-fast);
}
.studio-foot-link:hover {
  color: var(--color-oxblood);
  border-bottom-color: var(--color-oxblood);
}
@media (max-width: 600px) {
  .studio-foot-inner { gap: 0.85rem; }
  .studio-foot-meta { display: none; }
}

/* ============================================================ BOTTOM TABS (D.1) === */

/*
 * Mobile bottom tab bar — only renders on tenant pages (gated in the
 * partial) and only at <=720px (via the media query below). On wider
 * viewports the desktop topnav keeps its full link list; the bottom
 * bar is display:none.
 *
 * The "More" tab is a <details>/<summary>, same zero-JS pattern the
 * burger uses. Tapping it raises a bottom sheet with the long-tail
 * links. Tapping any tab navigates and dismisses the sheet on next
 * page render.
 */

.bottom-tabs {
  display: none;  /* Desktop: hidden. Mobile rule below flips it. */
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--color-bg);
  border-top: 1px solid var(--color-rule);
  z-index: 12;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.bottom-tab {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  padding: 0.5rem 0.25rem;
  min-height: 56px;
  color: var(--color-muted);
  text-decoration: none;
  font-family: var(--font-mono);
  font-size: var(--type-eyebrow);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  background: transparent;
  border: 0;
  list-style: none;
  -webkit-tap-highlight-color: transparent;
}
.bottom-tab::-webkit-details-marker { display: none; }
.bottom-tab::marker { content: ""; }
.bottom-tab:hover { color: var(--color-text); }
.bottom-tab--active { color: var(--color-oxblood); }
.bottom-tab--active .bottom-tab-icon svg { stroke-width: 2; }
.bottom-tab-icon { display: inline-flex; }
.bottom-tab-label { font-size: 10px; }
.bottom-tab:focus-visible {
  outline: 2px solid var(--color-oxblood);
  outline-offset: -2px;
  border-radius: 2px;
}

/* Bottom sheet for the "More" tab. <details> open state shows it.
 * .bottom-tab-more is itself a flex child of .bottom-tabs (flex: 1)
 * so it takes equal width with the other 4 tabs. Its <summary> child
 * gets the .bottom-tab class for visual consistency; the sheet div
 * is position:fixed so it doesn't disturb the tab-bar layout. */
.bottom-tab-more {
  flex: 1 1 0;
  display: flex;
}
.bottom-tab-more > summary {
  width: 100%;
  /* Inherit .bottom-tab styling — applied via class on the summary. */
}
.bottom-tab-more[open] > summary { color: var(--color-oxblood); }

.bottom-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 56px;  /* sit above the tab bar */
  bottom: calc(56px + env(safe-area-inset-bottom, 0));
  background: var(--color-bg);
  border-top: 1px solid var(--color-rule);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.08);
  z-index: 13;
  padding: 1rem 1.25rem 1.5rem;
  max-height: 60vh;
  overflow-y: auto;
}
.bottom-sheet-head {
  display: flex;
  align-items: center;
  margin-bottom: 0.6rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--color-rule);
}
.bottom-sheet-title {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  color: var(--color-oxblood);
}
.bottom-sheet-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
.bottom-sheet-list a,
.bottom-sheet-link {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.85rem 0.25rem;
  min-height: 44px;
  color: var(--color-text);
  font-family: var(--font-mono);
  font-size: var(--type-eyebrow);
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  text-decoration: none;
  background: transparent;
  border: 0;
  cursor: pointer;
}
.bottom-sheet-list a:hover,
.bottom-sheet-link:hover { color: var(--color-oxblood); }
.bottom-sheet-form { margin: 0; }
.bottom-sheet-divider {
  border-top: 1px solid var(--color-rule);
  margin: 0.4rem 0;
  height: 0;
  list-style: none;
}
.bottom-sheet-section {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--color-muted);
  padding: 0.9rem var(--app-card-pad) 0.25rem;
  list-style: none;
  border-top: 1px solid var(--color-rule);
  margin-top: 0.25rem;
}
.bottom-sheet-section:first-child {
  border-top: none;
  margin-top: 0;
  padding-top: 0.5rem;
}

/* Hide the burger inside tenant pages on mobile (bottom tabs replace it). */
.topnav-menu--hidden-on-tenant { display: none; }

@media (max-width: 720px) {
  .bottom-tabs { display: flex; }

  /* Reserve room at the bottom of <main> so content doesn't slide
     under the tab bar. The footer can stay below; user scrolls. */
  body > main.container { padding-bottom: calc(72px + env(safe-area-inset-bottom, 0)); }

  /* The burger menu was the mobile primary nav before D.1. Inside a
     tenant page the bottom tab bar takes over, so suppress the burger
     entirely there. Off-tenant pages (auth flow, picker, importer)
     still get the burger because there's no tab bar to replace it. */
  .topnav-menu--hidden-on-tenant { display: none !important; }
}

@media (min-width: 721px) {
  .bottom-tabs { display: none !important; }
}
