/* ALVIN AI - shared mobile navigation.
 *
 * Two patterns, both driven by static/js/app-shell.js (data-mnav-* attributes):
 *   1. Top-nav drawer   .mnav-drawer   slides in from the right (< 1024px)   landing, marketing
 *   2. Off-canvas side  .mnav-side     existing sidebar becomes a drawer     /app (< 768px), dashboard, admin (<= 768px)
 *
 * Everything is CLOSED by default in pure CSS, so a failed/slow script can never leave an
 * overlay open over the page. Desktop rendering is untouched: every rule below is either
 * scoped to a mobile media query or hidden (display:none) on desktop.
 */

/* ------------------------------------------------------------------ shared */
.mnav-toggle, .mnav-close {
  align-items: center; justify-content: center; flex: none;
  width: 40px; height: 40px; padding: 0; border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, .14); background: rgba(255, 255, 255, .05);
  color: #e5e7eb; cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: border-color .15s, background .15s;
}
.mnav-toggle { display: none; }
.mnav-close { display: inline-flex; }
.mnav-toggle:hover, .mnav-close:hover,
.mnav-toggle:focus-visible, .mnav-close:focus-visible { border-color: rgba(168, 85, 247, .65); background: rgba(168, 85, 247, .12); outline: none; }
.mnav-toggle svg, .mnav-close svg { width: 20px; height: 20px; pointer-events: none; }

.mnav-backdrop {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(3, 5, 12, .64); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .2s ease, visibility .2s;
}
.mnav-backdrop.is-open { opacity: 1; visibility: visible; pointer-events: auto; }

/* page scroll lock while a menu is open (released synchronously on close) */
html.mnav-lock, html.mnav-lock body { overflow: hidden !important; }

/* ------------------------------------------------- 1. top-nav drawer (right) */
.mnav-drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 2001;
  width: min(86vw, 330px); display: flex; flex-direction: column;
  overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(165deg, rgba(19, 27, 49, .99), rgba(10, 14, 26, .99));
  border-left: 1px solid rgba(6, 182, 212, .35);
  box-shadow: -30px 0 80px -20px rgba(0, 0, 0, .9);
  transform: translateX(104%); visibility: hidden; pointer-events: none;
  transition: transform .25s ease, visibility .25s;
}
.mnav-drawer.is-open { transform: none; visibility: visible; pointer-events: auto; }

.mnav-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.mnav-brand { display: flex; align-items: center; gap: 10px; min-width: 0; color: #fff; text-decoration: none; font-weight: 900; letter-spacing: .22em; font-size: 16px; }
.mnav-brand img { width: 36px; height: 36px; border-radius: 10px; background: #fff; object-fit: cover; flex: none; }
.mnav-label { margin: 14px 12px 6px; font-size: 10px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; color: #67e8f9; }
.mnav-link {
  display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 11px 12px; border-radius: 12px;
  font-size: 15px; font-weight: 600; color: #d1d5db; text-decoration: none; transition: background .15s, color .15s;
}
.mnav-link i, .mnav-link svg { width: 18px; text-align: center; color: #67e8f9; flex: none; }
.mnav-link:hover, .mnav-link:focus-visible { background: rgba(6, 182, 212, .1); color: #fff; outline: none; }
.mnav-link.mnav-back { color: #fff; border: 1px solid rgba(255, 255, 255, .14); margin-bottom: 4px; }
.mnav-cta { display: flex; flex-direction: column; gap: 10px; margin-top: auto; padding-top: 20px; }
.mnav-cta a { display: block; text-align: center; padding: 12px 18px; font-size: 14px; font-weight: 700; text-decoration: none; }

/* header items that make way for the burger so a 360px bar never overflows */
@media (max-width: 1023.98px) { .mnav-toggle:not(.mnav-toggle--side) { display: inline-flex; } }
@media (max-width: 639.98px)  { .mnav-hide-sm { display: none !important; } }
@media (max-width: 479.98px)  { .mnav-hide-xs { display: none !important; } }
/* the drawer can never exist on desktop */
@media (min-width: 1024px) {
  .mnav-drawer, .mnav-backdrop:not(.mnav-backdrop--side) { display: none !important; }
}

/* ------------------------------------- 2. off-canvas sidebar (left), < 768px */
.mnav-side-close { display: none; }
@media (max-width: 767.98px) {
  .mnav-toggle--side:not([data-bp="768"]) { display: inline-flex; }
  .mnav-side:not([data-bp="768"]) {
    position: fixed !important; top: 0; bottom: 0; left: 0; height: 100%; z-index: 2001;
    overflow-y: auto; overscroll-behavior: contain;
    transform: translateX(-104%); visibility: hidden; pointer-events: none;
    transition: transform .25s ease, visibility .25s;
  }
  .mnav-side:not([data-bp="768"]).is-open { transform: none; visibility: visible; pointer-events: auto; box-shadow: 30px 0 80px -20px rgba(0, 0, 0, .9); }
  .mnav-side:not([data-bp="768"]) .mnav-side-close { display: inline-flex; margin-left: auto; }
}
@media (min-width: 768px) { .mnav-backdrop--side:not([data-bp="768"]) { display: none !important; } }

/* dashboard / admin switch to their stacked layout at <= 768px */
.mnav-toggle--side[data-bp="768"] { display: none; }
@media (max-width: 768px) {
  .mnav-toggle--side[data-bp="768"] { display: inline-flex; }
  body > aside.mnav-side[data-bp="768"] {
    display: flex; position: fixed; top: 0; bottom: 0; left: 0; height: 100%; width: min(84vw, 288px); z-index: 2001;
    overflow-y: auto; overscroll-behavior: contain;
    transform: translateX(-104%); visibility: hidden; pointer-events: none;
    transition: transform .25s ease, visibility .25s;
  }
  body > aside.mnav-side[data-bp="768"].is-open { transform: none; visibility: visible; pointer-events: auto; box-shadow: 30px 0 80px -20px rgba(0, 0, 0, .9); }
  .mnav-side[data-bp="768"] .mnav-side-close { display: inline-flex; margin-left: auto; }
}
@media (min-width: 769px) { .mnav-backdrop--side[data-bp="768"] { display: none !important; } }

/* items that only exist inside the drawer form of a sidebar (e.g. "Back to Home") */
.mnav-only-lt768, .mnav-only-le768 { display: none; }
@media (max-width: 767.98px) { .mnav-only-lt768 { display: flex; } }
@media (max-width: 768px) { .mnav-only-le768 { display: flex; } }

@media (prefers-reduced-motion: reduce) {
  .mnav-drawer, .mnav-side, .mnav-backdrop { transition: none !important; }
}

/* a 360px top bar wraps instead of overflowing sideways (ai-tools) */
@media (max-width: 639.98px) { .mnav-wrap { flex-wrap: wrap; row-gap: 8px; } }

/* floating Back button (app-shell.js): keep it clear of the iOS home indicator */
#alvin-back { margin-bottom: env(safe-area-inset-bottom, 0px); }
