/*
 * foodbuddyz.css — shared design tokens, app-shell layout, auth gate, sidebar.
 *
 * Loaded from the <head> of every FoodBuddyz page. Works alongside each page's
 * own <style> block (page-specific layout + components stay inline).
 *
 * Plan: docs/plans/2026-04-21-002-feat-frontend-shell-shared-layout-login-plan.md
 */

/* ══════════════════════════════════════════════════════════════════════
 * Design tokens — UNION of :root blocks across the 4 feature pages.
 * Do not lift from a single page; pages define slightly different sets
 * (grocery-list adds --radius-lg, --shadow-soft, --shadow-lift).
 * ══════════════════════════════════════════════════════════════════════ */
:root {
  /* Greens */
  --green-deep: #0f2e1f;
  --green-mid: #1a4a32;
  --green-bright: #2d7a50;
  --green-light: #e8f5e9;
  --green-muted: #d4e8da;

  /* Accents */
  --amber: #e8a838;
  --amber-light: #f5d590;
  --amber-bg: #fef8eb;
  --coral: #d4654a;
  --coral-light: #f0a090;
  --coral-bg: #fde8e3;

  /* Neutrals */
  --cream: #faf6ee;
  --cream-dark: #f0e8d8;
  --ink: #1a1a18;
  --ink-light: #5a5a52;
  --ink-muted: #9a9a90;
  --white: #ffffff;

  /* Layout */
  --sidebar-w: 260px;

  /* Typography */
  --font-display: 'Fraunces', serif;
  --font-body: 'Outfit', sans-serif;

  /* Shape tokens — superset */
  --radius: 16px;
  --radius-sm: 10px;
  --radius-lg: 24px;

  /* Shadow tokens — superset */
  --shadow-soft: 0 2px 12px rgba(0, 0, 0, 0.03);
  --shadow-lift: 0 12px 36px rgba(15, 46, 31, 0.14);
}

/* ══════════════════════════════════════════════════════════════════════
 * App-shell layout: reserves sidebar space via body padding-left, AND
 * overrides each retrofitted page's inline .main { margin-left,
 * max-width } rules so there's ONE source of truth for sidebar
 * reservation. This prevents the "main fills 70% of viewport" bug that
 * can happen when max-width: calc(100% - N) interacts badly with flex
 * layout, browser zoom, or DevTools-docked-right rendering.
 *
 * Selector html.fbz-app-shell body > main.main has specificity (0,2,2)
 * which beats any page's inline `.main { ... }` (specificity 0,1,0)
 * without needing !important.
 * ══════════════════════════════════════════════════════════════════════ */
html.fbz-app-shell,
html.fbz-app-shell body {
  min-height: 100vh;
}

html.fbz-app-shell body {
  padding-left: var(--sidebar-w);
}

html.fbz-app-shell body > main.main {
  margin-left: 0;
  max-width: none;
  width: 100%;
}

/* Each page's inline `body { overflow-x: hidden }` implicitly flips
 * overflow-y to `auto` (CSS spec quirk), which turns body into its own
 * vertical scroll container and can prevent the document from scrolling
 * to the bottom. Reset overflow on body so the html/viewport is the
 * single scroll context. Any horizontal overflow gets clipped by the
 * html level instead. */
html.fbz-app-shell body {
  overflow: visible;
}
html.fbz-app-shell {
  overflow-x: clip;
}

@media (max-width: 768px) {
  html.fbz-app-shell body {
    padding-left: 0;
  }
}

/* ══════════════════════════════════════════════════════════════════════
 * Auth gate: hides body content until requireLogin() resolves OR the
 * 3-second failsafe timeout fires (set by inline <head> script on each
 * protected page). Uses visibility (not opacity) so clicks don't fire
 * in the blank window. Applied only on pages with fbz-gate-auth class.
 * ══════════════════════════════════════════════════════════════════════ */
html.fbz-gate-auth body {
  visibility: hidden;
}

html.fbz-gate-auth.fbz-gate-resolved body {
  visibility: visible;
}

/* ══════════════════════════════════════════════════════════════════════
 * Sidebar — shared markup rendered by FoodBuddyz.renderSidebar().
 * Matches the existing per-page sidebar visually. Do not add per-page
 * variants here; page-specific overrides belong in each page's <style>.
 * ══════════════════════════════════════════════════════════════════════ */
.fbz-sidebar,
aside.sidebar {
  width: var(--sidebar-w);
  background: var(--green-deep);
  padding: 2rem 1.2rem;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 10;
  font-family: var(--font-body);
}

.fbz-sidebar-logo {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.4rem;
  color: var(--white);
  padding: 0 0.6rem;
  margin-bottom: 2.5rem;
  text-decoration: none;
  display: block;
}

.fbz-sidebar-logo span {
  color: var(--amber);
}

.fbz-sidebar-nav {
  list-style: none;
  flex: 1;
  margin: 0;
  padding: 0;
}

.fbz-sidebar-nav li {
  margin-bottom: 0.25rem;
}

.fbz-sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.75rem 0.8rem;
  border-radius: var(--radius-sm);
  color: rgba(255, 255, 255, 0.5);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s;
}

.fbz-sidebar-nav a:hover {
  color: rgba(255, 255, 255, 0.8);
  background: rgba(255, 255, 255, 0.06);
}

.fbz-sidebar-nav a.active {
  color: var(--white);
  background: rgba(255, 255, 255, 0.1);
}

.fbz-sidebar-nav .nav-icon {
  width: 20px;
  text-align: center;
  font-size: 1rem;
}

.fbz-sidebar-section {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: rgba(255, 255, 255, 0.25);
  padding: 1.5rem 0.8rem 0.5rem;
  list-style: none;
}

.fbz-sidebar-bottom {
  padding: 1rem 0.6rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.fbz-sidebar-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--amber);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--green-deep);
  flex-shrink: 0;
}

.fbz-sidebar-user-name {
  color: var(--white);
  font-size: 0.88rem;
  font-weight: 500;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 150px;
  white-space: nowrap;
}

.fbz-sidebar-user-plan {
  color: rgba(255, 255, 255, 0.4);
  font-size: 0.72rem;
  font-weight: 400;
  margin-top: 0.15rem;
}

.fbz-sidebar-signout {
  color: var(--coral-light);
  font-size: 0.72rem;
  font-weight: 500;
  text-decoration: none;
  margin-top: 0.15rem;
  display: inline-block;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
}

.fbz-sidebar-signout:hover {
  color: var(--coral);
  text-decoration: underline;
}

.fbz-sidebar-signin {
  color: var(--amber);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  padding: 0.5rem 0.8rem;
  border: 1px solid var(--amber);
  border-radius: var(--radius-sm);
  display: inline-block;
}

.fbz-sidebar-signin:hover {
  background: var(--amber);
  color: var(--green-deep);
}

.fbz-sidebar-try-demo {
  color: rgba(255, 255, 255, 0.5);
  font-size: 0.7rem;
  text-decoration: underline;
  margin-top: 0.75rem;
  display: block;
  background: none;
  border: none;
  padding: 0.3rem 0;
  cursor: pointer;
}

.fbz-sidebar-try-demo:hover {
  color: var(--amber);
}

/* ══════════════════════════════════════════════════════════════════════
 * Private-browsing banner (shown once when localStorage unavailable).
 * ══════════════════════════════════════════════════════════════════════ */
.fbz-private-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: var(--coral-bg);
  color: var(--green-deep);
  padding: 0.6rem 1rem;
  font-size: 0.82rem;
  font-family: var(--font-body);
  text-align: center;
  z-index: 100;
  border-bottom: 1px solid var(--coral-light);
}

.fbz-private-banner button {
  background: none;
  border: none;
  color: var(--green-deep);
  font-weight: 600;
  cursor: pointer;
  margin-left: 0.5rem;
  text-decoration: underline;
}
