/* ==========================================================================
   GATE PASS — App Shell Layout
   Gate Pass app shell.
   Navy sidebar (authority) + light content (clarity) + gold accents (premium).
   ========================================================================== */

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: var(--header-height) 1fr;
  grid-template-areas:
    "sidebar header"
    "sidebar main";
  min-height: 100vh;
  min-height: 100dvh;
}

/* ============================================================
   SIDEBAR — Navy with gold accent
   ============================================================ */
.app-sidebar {
  grid-area: sidebar;
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  border-right: 1px solid var(--sidebar-border);
  z-index: var(--z-sidebar);
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-color: rgba(255,255,255,0.15) transparent;
}

.app-sidebar::-webkit-scrollbar { width: 6px; }
.app-sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }

/* Brand block — owl mark + wordmark */
.app-sidebar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  height: var(--header-height);
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
  text-decoration: none;
}

.app-sidebar__brand:hover { text-decoration: none; }

.app-sidebar__brand .brand-mark {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-accent-500);
  color: var(--color-primary-900);
  border-radius: var(--radius-md);
  flex-shrink: 0;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2), inset 0 1px 0 rgba(255,255,255,0.2);
}
.app-sidebar__brand .brand-mark svg { width: 22px; height: 22px; }

.app-sidebar__brand .brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}
.app-sidebar__brand .brand-name {
  font-size: 14px;
  font-weight: var(--weight-bold);
  color: var(--sidebar-brand);
  letter-spacing: 0.02em;
}
.app-sidebar__brand .brand-tag {
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  color: var(--color-accent-300);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 2px;
}

/* Nav section */
.app-sidebar__section {
  padding: 16px 12px 12px;
  flex: 1;
}
.app-sidebar__section-label {
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  color: rgba(255,255,255,0.4);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0 12px 8px;
}
/* Inline label inside a nav list — used for "System tools" break */
.app-sidebar__section-label--inset {
  padding: 16px 12px 6px;
  border-top: 1px solid var(--sidebar-border);
  margin-top: 12px;
}

.app-nav { display: flex; flex-direction: column; gap: 2px; }

.app-nav__link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  color: var(--sidebar-text);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  text-decoration: none;
  transition: background var(--duration-fast), color var(--duration-fast);
  min-height: 36px;
  position: relative;
  white-space: nowrap;
}
.app-nav__link .nav-icon {
  width: 18px; height: 18px;
  flex-shrink: 0;
  opacity: 0.7;
  transition: opacity var(--duration-fast);
}
.app-nav__link:hover {
  background: rgba(255,255,255,0.06);
  color: var(--sidebar-text-hover);
  text-decoration: none;
}
.app-nav__link:hover .nav-icon { opacity: 1; }

.app-nav__link[aria-current="page"] {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
}
.app-nav__link[aria-current="page"] .nav-icon { opacity: 1; }
.app-nav__link[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 6px; bottom: 6px;
  width: 3px;
  background: var(--color-accent-500);
  border-radius: 0 2px 2px 0;
}

/* Sidebar footer (reserved for future user/profile area) */
.app-sidebar__footer {
  padding: 12px;
  border-top: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

/* ============================================================
   HEADER
   ============================================================ */
.app-header {
  grid-area: header;
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  display: flex;
  align-items: center;
  gap: 12px;
  padding-inline: 24px;
  background: var(--surface-raised);
  border-bottom: 1px solid var(--surface-border);
  height: var(--header-height);
}

.app-header__title {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  letter-spacing: var(--tracking-tight);
}

/* Brand mark is mobile-only (desktop sidebar carries the full brand). */
.app-header__mark { display: none; }

.app-header__spacer { flex: 1; }

.app-header__menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
}
.app-header__menu-btn:hover { background: var(--surface-sunken); color: var(--text-primary); }

/* ============================================================
   MAIN
   ============================================================ */
.app-main {
  grid-area: main;
  overflow-y: auto;
  padding: 32px;
  background: var(--surface-page);
}

/* Mobile scrim — light dim, NO blur (was making menu hard to read).
   Sits BELOW the sidebar so the drawer renders crisp on top. */
.app-scrim {
  position: fixed; inset: 0;
  background: rgba(15,23,42,0.4);
  z-index: var(--z-overlay);
  opacity: 0; visibility: hidden;
  transition:
    opacity var(--duration-base) var(--ease-out),
    visibility var(--duration-base) var(--ease-out);
}

/* ============================================================
   AUTH ROOT — fills viewport so the card centers correctly
   ============================================================ */
#auth-root {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1023px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas: "header" "main";
  }
  .app-sidebar {
    position: fixed;
    inset-block: 0; inset-inline-start: 0;
    width: var(--sidebar-width);
    transform: translateX(-100%);
    transition: transform var(--duration-base) var(--ease-out);
    box-shadow: var(--shadow-xl);
    z-index: var(--z-drawer); /* sit ABOVE scrim so taps reach nav items */
    /* Respect iPhone safe areas (notch / home indicator) */
    padding-top: env(safe-area-inset-top, 0);
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .app-shell[data-sidebar-open="true"] .app-sidebar { transform: translateX(0); }
  .app-shell[data-sidebar-open="true"] .app-scrim { opacity: 1; visibility: visible; }
  .app-header__menu-btn {
    display: inline-flex;
    /* Apple HIG: 44pt minimum. Mobile menu trigger MUST be tappable. */
    width: 44px;
    height: 44px;
  }
  .app-main {
    padding: 20px 16px;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
  }
  /* Header respects status-bar inset when running as standalone PWA */
  .app-header {
    padding-top: env(safe-area-inset-top, 0);
    height: calc(var(--header-height) + env(safe-area-inset-top, 0));
    padding-inline: max(16px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-right));
  }
  /* Bump nav links to a proper touch target on mobile */
  .app-nav__link {
    min-height: 44px;
    padding-block: 11px;
  }
  /* The mobile sidebar is opened via the bottom bar's "More" button, so it
     should show ONLY overflow destinations — hide anything that already
     has its own bottom-bar tab. (No-op on desktop where the bar is hidden
     and the sidebar is the sole nav.) */
  .app-nav__link--in-tabbar { display: none; }
  /* User-area logout button — easier to tap */
  .user-area__logout {
    height: 40px;
    padding: 0 14px;
  }
}

@media (min-width: 1024px) {
  .app-header__menu-btn { display: none; }
}

/* Super-admin mode banner (shown in app-main, above container) ----------- */
.super-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: #fff8e1;
  border-bottom: 1px solid #f0c948;
  color: #6b4f00;
  font-size: 12px;
  font-weight: 500;
}
.super-banner svg { flex-shrink: 0; }
/* Breathing room so the page title underneath isn't crammed against the banner. */
.super-banner { margin-bottom: 10px; }
