/* ==========================================================================
   NEARBY CHAT — RESPONSIVE LAYOUT & NAVIGATION
   ========================================================================== */

/* Main App Shell */
.app-container {
  min-height: 100vh;
  width: 100%;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-app);
  overflow-x: hidden;
}

/* Top App Header */
.app-header {
  position: sticky;
  top: 0;
  width: 100%;
  max-width: 100%;
  height: var(--header-height);
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-4);
  box-sizing: border-box;
}

.header-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 700;
  font-size: var(--text-lg);
  color: var(--text-primary);
  text-decoration: none;
  white-space: nowrap;
}

.brand-logo img, .brand-logo svg {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

.header-page-title {
  font-size: var(--text-lg);
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.3px;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

@media (max-width: 480px) {
  .header-page-title {
    font-size: var(--text-base);
  }
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

/* Desktop Nav Items (hidden on mobile) */
.desktop-nav {
  display: none;
}

/* Main Content Area */
.app-main {
  flex: 1;
  width: 100%;
  max-width: var(--max-content-width);
  margin: 0 auto;
  padding: var(--space-4);
  padding-bottom: calc(var(--bottom-nav-height) + var(--space-6)); /* Space for mobile nav */
  box-sizing: border-box;
  min-width: 0;
}

/* Chat Page Content Isolation */
html:has(body.is-chat-page),
body.is-chat-page {
  height: 100%;
  height: 100dvh;
  margin: 0;
  padding: 0;
  overflow: hidden;
  position: fixed;
  width: 100%;
  left: 0;
  top: 0;
}

body.is-chat-page .app-container {
  height: 100%;
  height: var(--visual-viewport-height, 100dvh);
  max-height: var(--visual-viewport-height, 100dvh);
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

@media (max-width: 767px) {
  /* On mobile chat screens, hide the redundant global header and bottom nav */
  body.is-chat-page .app-header {
    display: none !important;
  }
  body.is-chat-page .bottom-nav {
    display: none !important;
  }

  body.is-chat-page .app-main {
    flex: 1 1 0%;
    min-height: 0;
    height: 100%;
    padding: 0 !important;
    margin: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
}

@media (min-width: 768px) {
  body.is-chat-page {
    position: relative;
    overflow: auto;
  }
  body.is-chat-page .app-container {
    height: 100vh;
    height: 100dvh;
    max-height: 100dvh;
  }
  body.is-chat-page .app-main {
    flex: 1;
    min-height: 0;
    max-width: var(--max-content-width);
    margin: 0 auto;
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
}

/* Auth Pages Wrapper */
.auth-wrapper {
  width: 100%;
  max-width: 440px;
  margin: var(--space-6) auto;
  padding: 0;
  box-sizing: border-box;
}

/* Mobile Bottom Navigation Bar (Home | Chats | Rooms | Profile) */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottom-nav-height);
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 500;
  padding: 0 var(--space-2);
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: 600;
  text-decoration: none;
  flex: 1;
  height: 100%;
  position: relative;
  transition: color var(--transition-fast);
}

.bottom-nav-item.active {
  color: var(--primary);
}

.bottom-nav-item svg {
  width: 22px;
  height: 22px;
  stroke-width: 2.2;
}

.nav-badge {
  position: absolute;
  top: 6px;
  right: calc(50% - 18px);
  background-color: var(--primary);
  color: var(--text-inverse);
  font-size: 10px;
  font-weight: 700;
  border-radius: var(--radius-full);
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg-surface);
}

/* ==========================================================================
   DESKTOP RESPONSIVENESS (>= 768px)
   ========================================================================== */
@media (min-width: 768px) {
  .app-header {
    padding: 0 var(--space-8);
  }

  .desktop-nav {
    display: flex;
    align-items: center;
    gap: var(--space-6);
  }

  .desktop-nav-link {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-secondary);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    position: relative;
  }

  .desktop-nav-link:hover {
    color: var(--primary);
    background-color: var(--primary-light);
  }

  .desktop-nav-link.active {
    color: var(--primary);
    background-color: var(--primary-light);
  }

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

  .app-main {
    padding: var(--space-6) var(--space-8);
    padding-bottom: var(--space-10);
  }

  /* Grid Layouts for discovery & rooms */
  .grid-discovery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: var(--space-4);
  }

  .grid-rooms {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--space-4);
  }
}
