/*
 * Mobile navbar drawer — peer-checked fallback + polish.
 *
 * The compiled Tailwind bundle (tailwind-main.css) currently ships without
 * peer-checked variants, so the markup class `peer-checked:flex` on
 * #mobile-nav-drawer has no effect and the hamburger toggle never opens
 * the drawer. This file implements the :checked sibling selector directly
 * so the pure-CSS hamburger works regardless of the Tailwind build state.
 *
 * It also paints a polished mobile drawer: card-style surface, gradient
 * accent, slide-down animation, full-viewport backdrop, and a clearly
 * themed close button.
 *
 * Selector contract (do not change these ids without updating base.html):
 *   - #mobile-nav-toggle     : the <input type="checkbox"> driver
 *   - #mobile-nav-toggle-btn : the <label> that flips the checkbox
 *   - #mobile-nav-drawer     : the drawer panel that should slide in
 *   - #mobile-nav-backdrop   : the dim/blur backdrop behind the drawer
 */

/* ── Open the drawer when the hamburger checkbox is checked ───────────── */
#mobile-nav-toggle:checked ~ #mobile-nav-drawer {
  display: flex !important;
  animation: mobileNavDrawerIn 220ms ease-out both;
}

#mobile-nav-toggle:checked ~ #mobile-nav-backdrop {
  display: block !important;
  animation: mobileNavBackdropIn 220ms ease-out both;
}

/* While the drawer is open, hide the navbar-level hamburger button
 * completely — the drawer provides its OWN in-panel close control
 * (.mobile-nav-drawer__close), and we no longer want a floating
 * ✕ glyph outside the panel (the previous design placed the close
 * on the navbar bar, visually disconnected from the drawer card). */
#mobile-nav-toggle:checked ~ #mobile-nav-toggle-btn {
  visibility: hidden;
  pointer-events: none;
}

/* ── Polished drawer surface: compact right-anchored panel ───────────── *
 * Anchored to the top-right corner where the hamburger sits, so the
 * panel feels like a dropdown extending from the trigger rather than a
 * full-viewport sheet. Width is capped so it doesn't dominate the
 * screen, and rows are tightened so all entries fit without scrolling
 * on a typical 640dvh phone. */
.mobile-nav-drawer {
  position: fixed;
  top: 8px;
  right: 8px;
  left: auto;
  z-index: 50;
  width: min(280px, calc(100vw - 16px));
  max-height: calc(100dvh - 16px);
  overflow-y: auto;
  background: linear-gradient(180deg, #111827 0%, #0b1220 100%);
  border: 1px solid rgba(55, 65, 81, 0.7);
  border-radius: 14px;
  padding: 8px 8px 10px;
  margin-top: 0;
  box-shadow:
    0 20px 40px -10px rgba(0, 0, 0, 0.55),
    0 0 0 1px rgba(255, 255, 255, 0.03) inset;
  gap: 2px;
}

/* Green→blue accent stripe across the top */
.mobile-nav-drawer::before {
  content: "";
  display: block;
  height: 2px;
  border-radius: 2px;
  margin: 0 4px 6px;
  background: linear-gradient(90deg,
              rgba(34, 197, 94, 0.8) 0%,
              rgba(52, 211, 153, 0.7) 50%,
              rgba(59, 130, 246, 0.7) 100%);
}

/* ── In-panel header: logo + close button together ───────────────────── *
 * The previous layout left the KAIS logo on the navbar and the ✕ on
 * the navbar, with the drawer card floating below. We now surface the
 * logo and close inside the drawer so they visually belong to the
 * same panel as the nav items. */
.mobile-nav-drawer__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 2px 6px;
  margin-bottom: 4px;
  border-bottom: 1px solid rgba(55, 65, 81, 0.5);
}

.mobile-nav-drawer__brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #f3f4f6;
  text-decoration: none;
  border-radius: 6px;
  padding: 2px 4px;
  transition: background-color 150ms ease;
}

.mobile-nav-drawer__brand:hover,
.mobile-nav-drawer__brand:focus-visible {
  background: rgba(255, 255, 255, 0.05);
  outline: none;
}

.mobile-nav-drawer__logo {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  object-fit: contain;
  display: block;
}

.mobile-nav-drawer__brand-text {
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.02em;
  color: #f9fafb;
}

.mobile-nav-drawer__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  color: #e5e7eb;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(55, 65, 81, 0.6);
  cursor: pointer;
  transition: background-color 150ms ease,
              border-color 150ms ease,
              color 150ms ease;
}

.mobile-nav-drawer__close:hover,
.mobile-nav-drawer__close:focus-visible {
  background: rgba(34, 197, 94, 0.14);
  border-color: rgba(34, 197, 94, 0.45);
  color: #4ade80;
  outline: none;
}

.mobile-nav-drawer__close:active {
  transform: scale(0.96);
}

.mobile-nav-drawer__close svg {
  display: block;
}

/* Anchor / button rows inside the drawer */
.mobile-nav-drawer > a,
.mobile-nav-drawer > form > button {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 8px;
  color: #f3f4f6;
  font-weight: 600;
  font-size: 13px;
  line-height: 1.2;
  border: 1px solid transparent;
  transition: background-color 150ms ease,
              border-color 150ms ease,
              transform 120ms ease;
  text-decoration: none;
  width: 100%;
  text-align: left;
  background: transparent;
}

.mobile-nav-drawer > a:hover,
.mobile-nav-drawer > a:focus-visible,
.mobile-nav-drawer > form > button:hover,
.mobile-nav-drawer > form > button:focus-visible {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(34, 197, 94, 0.35);
  transform: translateX(2px);
  outline: none;
}

.mobile-nav-drawer > a:active,
.mobile-nav-drawer > form > button:active {
  transform: translateX(0) scale(0.99);
}

/* Tighten SVG icons inside drawer rows */
.mobile-nav-drawer > a > svg,
.mobile-nav-drawer > form > button > svg,
.mobile-nav-profile > svg,
.mobile-nav-profile .nav-avatar,
.mobile-nav-profile .nav-avatar-initials {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* Profile row: smaller avatar + tighter padding */
.mobile-nav-profile {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 600;
  color: #f3f4f6;
  text-decoration: none;
  border-radius: 8px;
}

.mobile-nav-profile .nav-avatar,
.mobile-nav-profile .nav-avatar-initials {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.06);
  font-size: 11px;
  font-weight: 700;
  color: #f3f4f6;
}

/* Subtle separator before the logout form */
.mobile-nav-drawer > form {
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px solid rgba(55, 65, 81, 0.6);
}

/* Coin pill: keep compact and self-contained */
.mobile-nav-drawer .coin-display {
  align-self: flex-start;
  margin: 2px 4px 4px;
  padding: 2px 8px;
  font-size: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.mobile-nav-drawer .coin-display .coin-symbol svg {
  width: 14px;
  height: 14px;
}

/* ── Navbar row on mobile ────────────────────────────────────────────── *
 * tailwind-main.css ships a ``.navbar { flex-direction: column; }`` rule
 * at ≤640px which stacks the logo and the hamburger trigger on separate
 * rows (the hamburger ends up beneath the logo). That predates the
 * peer-checked drawer, which expects the trigger to sit on the SAME
 * row as the logo, anchored to the right. Pin the row to horizontal
 * and right-align the hamburger; keep auth/nav siblings hidden on
 * mobile (they are ``hidden md:flex`` in markup but the stacked
 * navbar reserved vertical space for them regardless). */
@media (max-width: 640px) {
  .navbar {
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    justify-content: space-between !important;
  }
  .navbar .logo {
    margin-bottom: 0 !important;
  }
  .navbar .logo img {
    max-height: 40px;
  }
  #mobile-nav-toggle-btn {
    margin-left: auto;
  }
}

/* ── Backdrop ────────────────────────────────────────────────────────── */
#mobile-nav-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(3, 7, 18, 0.55);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  z-index: 30;
}

/* ── Animations ──────────────────────────────────────────────────────── */
@keyframes mobileNavDrawerIn {
  from {
    opacity: 0;
    transform: translateY(-16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes mobileNavBackdropIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Respect user motion preferences */
@media (prefers-reduced-motion: reduce) {
  #mobile-nav-toggle:checked ~ #mobile-nav-drawer,
  #mobile-nav-toggle:checked ~ #mobile-nav-backdrop {
    animation: none;
  }
  .mobile-nav-drawer > a,
  .mobile-nav-drawer > form > button {
    transition: none;
  }
}

/* ── Desktop (md and up): force hamburger + drawer hidden ────────────── *
 * Tailwind's `.inline-flex` utility is emitted AFTER `.md\:hidden` in the
 * compiled bundle, so at ≥768px the later rule wins and the hamburger
 * stays visible on desktop. Force it hidden here. */
@media (min-width: 768px) {
  #mobile-nav-toggle-btn,
  #mobile-nav-drawer,
  #mobile-nav-backdrop {
    display: none !important;
  }
  /* Defensive: even if the checkbox is somehow :checked (e.g. device
   * rotation from mobile to desktop width) the drawer must not expand
   * the navbar row. */
  #mobile-nav-toggle:checked ~ #mobile-nav-drawer,
  #mobile-nav-toggle:checked ~ #mobile-nav-backdrop {
    display: none !important;
  }
  #mobile-nav-toggle {
    display: none !important;
  }
}
