/**
 * LAYOUT - Premium Mobile-First
 */

/* ============================================
   APP HEADER - Fixed top bar
   ============================================ */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-primary);
  z-index: var(--z-fixed);
  padding-top: var(--safe-area-inset-top);
}

.app-header__container {
  height: 100%;
  max-width: var(--container-xl);
  margin: 0 auto;
  padding: 0 var(--space-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-header__brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  text-decoration: none;
  color: var(--text-primary);
}

.app-header__logo {
  height: 32px;
  width: auto;
}

.app-header__title {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  display: none;
}

.app-header__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* ============================================
   MAIN CONTENT AREA
   ============================================ */
.app-main {
  min-height: 100vh;
  padding-top: calc(var(--header-height) + var(--safe-area-inset-top));
  padding-bottom: calc(72px + var(--safe-area-inset-bottom)); /* Space for bottom nav */
}

/* ============================================
   MOBILE BOTTOM NAVIGATION
   ============================================ */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(64px + var(--safe-area-inset-bottom));
  background: var(--bg-primary);
  border-top: 1px solid var(--border-primary);
  display: flex;
  justify-content: space-around;
  align-items: flex-start;
  padding: var(--space-2) 0 var(--safe-area-inset-bottom);
  z-index: var(--z-fixed);
  backdrop-filter: blur(10px);
  background: rgba(255, 255, 255, 0.9);
}

@media (prefers-color-scheme: dark) {
  .bottom-nav {
    background: rgba(23, 23, 23, 0.9);
  }
}

body.dark-mode .bottom-nav {
  background: rgba(23, 23, 23, 0.9);
}

.bottom-nav__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-2);
  text-decoration: none;
  color: var(--text-tertiary);
  transition: color var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.bottom-nav__item.active {
  color: var(--accent-primary);
}

.bottom-nav__icon {
  font-size: 24px;
  line-height: 1;
}

.bottom-nav__label {
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
}

/* ============================================
   DESKTOP NAVIGATION
   ============================================ */
.desktop-nav {
  display: none;
}

/* ============================================
   MOBILE MENU DRAWER
   ============================================ */
.mobile-menu {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 85%;
  max-width: 320px;
  background: var(--bg-primary);
  z-index: var(--z-modal);
  transform: translateX(100%);
  transition: transform var(--transition-slow) var(--ease-out);
  overflow-y: auto;
  padding: var(--safe-area-inset-top) 0 var(--safe-area-inset-bottom);
}

.mobile-menu.active {
  transform: translateX(0);
}

.mobile-menu__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-6) var(--space-6) var(--space-4);
}

.mobile-menu__title {
  font-size: var(--text-2xl);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
}

.mobile-menu__content {
  padding: 0 var(--space-4);
}

.mobile-menu-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: calc(var(--z-modal) - 1);
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-base);
  backdrop-filter: blur(4px);
}

.mobile-menu-backdrop.active {
  opacity: 1;
  visibility: visible;
}

/* ============================================
   DESKTOP LAYOUT
   ============================================ */
@media (min-width: 768px) {
  /* Show desktop nav */
  .desktop-nav {
    display: block;
    position: fixed;
    top: calc(var(--header-height-desktop) + var(--safe-area-inset-top));
    left: 0;
    width: 200px;
    height: calc(100vh - var(--header-height-desktop) - var(--safe-area-inset-top));
    background: var(--bg-primary);
    border-right: 1px solid var(--border-primary);
    padding: var(--space-6) 0;
    z-index: var(--z-sticky);
  }

  .desktop-nav__container {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    padding: 0 var(--space-3);
  }

  .desktop-nav__item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    text-decoration: none;
    color: var(--text-secondary);
    font-weight: var(--font-medium);
    font-size: var(--text-sm);
    border-radius: var(--radius-lg);
    transition: all var(--transition-fast);
  }

  .desktop-nav__item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
  }

  .desktop-nav__item.active {
    background: var(--accent-primary);
    color: var(--color-white);
  }

  .desktop-nav__icon {
    font-size: 20px;
  }

  /* Hide mobile nav */
  .bottom-nav {
    display: none;
  }

  /* Hide mobile menu button */
  #mobile-menu-btn {
    display: none;
  }

  /* Adjust header */
  .app-header {
    height: var(--header-height-desktop);
  }

  .app-header__title {
    display: block;
  }

  /* Adjust main content */
  .app-main {
    margin-left: 200px;
    padding-top: calc(var(--header-height-desktop) + var(--safe-area-inset-top));
    padding-bottom: 0;
  }
}

@media (min-width: 1024px) {
  .desktop-nav {
    width: 240px;
  }

  .app-main {
    margin-left: 240px;
  }

  .desktop-nav__item {
    font-size: var(--text-base);
  }
}

/* ============================================
   CONTAINER UTILITIES
   ============================================ */
.container {
  width: 100%;
  max-width: var(--container-xl);
  margin: 0 auto;
  padding: 0 var(--space-4);
}

.container--sm {
  max-width: var(--container-sm);
}

.container--md {
  max-width: var(--container-md);
}

.container--lg {
  max-width: var(--container-lg);
}

@media (min-width: 768px) {
  .container {
    padding: 0 var(--space-8);
  }
}

/* ============================================
   PAGE CONTENT UTILITIES
   ============================================ */
.page-header {
  padding: var(--space-6) 0 var(--space-4);
}

.page-title {
  font-size: var(--text-3xl);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}

.page-subtitle {
  font-size: var(--text-base);
  color: var(--text-secondary);
}

.page-section {
  padding: var(--space-6) 0;
}

.section-title {
  font-size: var(--text-xl);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  margin-bottom: var(--space-4);
}

/* ============================================
   UTILITY CLASSES
   ============================================ */
.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

.text-center {
  text-align: center;
}

.text-right {
  text-align: right;
}

/* Flex utilities */
.flex {
  display: flex;
}

.flex-col {
  flex-direction: column;
}

.items-center {
  align-items: center;
}

.justify-center {
  justify-content: center;
}

.justify-between {
  justify-content: space-between;
}

.gap-2 {
  gap: var(--space-2);
}

.gap-4 {
  gap: var(--space-4);
}

.gap-6 {
  gap: var(--space-6);
}

/* Grid utilities */
.grid {
  display: grid;
}

.grid-cols-2 {
  grid-template-columns: repeat(2, 1fr);
}

.grid-cols-3 {
  grid-template-columns: repeat(3, 1fr);
}

@media (min-width: 768px) {
  .md\:grid-cols-2 {
    grid-template-columns: repeat(2, 1fr);
  }

  .md\:grid-cols-3 {
    grid-template-columns: repeat(3, 1fr);
  }

  .md\:grid-cols-4 {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* ============================================
   USER BADGE (header)
   ============================================ */
.user-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.user-badge__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  flex-shrink: 0;
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4); }
  50% { opacity: 0.7; box-shadow: 0 0 0 4px rgba(34, 197, 94, 0); }
}

.user-badge__info {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.user-badge__name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
}

.user-badge__username {
  font-size: 0.65rem;
  color: var(--text-secondary);
}

@media (max-width: 480px) {
  .user-badge__name {
    font-size: 0.7rem;
  }
  .user-badge__username {
    font-size: 0.6rem;
  }
}
