/* =========================================
   NAK — Mobile & PWA layout fixes
========================================= */

html {
  overflow-x: clip;
  -webkit-text-size-adjust: 100%;
}

body {
  overflow-x: clip;
  max-width: 100%;
  width: 100%;
}

body.page-chat,
body.page-home {
  overflow-x: hidden;
  touch-action: pan-y;
}

img,
video,
svg {
  max-width: 100%;
}

/* ---- Mobile typography: slightly smaller; desktop unchanged ---- */
@media (max-width: 991px) {
  html {
    font-size: 15px;
  }
}

/* ---- Prevent iOS zoom on input focus (must stay >= 16px) ---- */
@media (max-width: 991px) {
  input,
  textarea,
  select,
  .form-control {
    font-size: 16px !important;
  }
}

/* ---- Compact top bar on phones ---- */
@media (max-width: 991px) {
  :root {
    --navbar-height: 46px;
    --mobile-bottom-bar: calc(56px + 10px + var(--safe-bottom));
  }

  #mainNavbar {
    height: calc(var(--navbar-height) + var(--safe-top));
    min-height: calc(var(--navbar-height) + var(--safe-top));
    max-height: calc(var(--navbar-height) + var(--safe-top));
    padding-top: var(--safe-top) !important;
    padding-bottom: 0 !important;
    box-sizing: border-box;
  }

  .nav-container {
    height: var(--navbar-height);
    min-height: var(--navbar-height) !important;
    max-height: var(--navbar-height);
    padding-top: 2px !important;
    padding-bottom: 2px !important;
  }

  .navbar-brand {
    font-size: 0.98rem;
    gap: 8px;
  }

  .navbar-brand img {
    width: 30px !important;
    height: 30px !important;
  }

  /* Footer layout for inner pages → mobile_ux.css */
}

/* ---- Bottom nav: fewer items on small screens ---- */
@media (max-width: 576px) {
  :root {
    --mobile-bottom-bar: calc(50px + 8px + var(--safe-bottom));
  }

  .mobile-bottom-nav {
    height: 50px;
    border-radius: 16px;
    padding: 0 2px;
    bottom: calc(8px + var(--safe-bottom));
  }

  .mobile-bottom-nav .profile-block,
  .mobile-bottom-nav a[href*="change_password"] {
    display: none !important;
  }

  .mobile-nav-link {
    font-size: 0.62rem;
    gap: 3px;
    min-width: 0;
  }

  .mobile-nav-link i,
  #mobileThemeEmoji {
    font-size: 1.2rem;
  }
}

/* =========================================
   CHAT — full-height layout + inner scroll
========================================= */

body.page-chat {
  overflow: hidden;
  height: 100dvh;
  width: 100%;
  max-width: 100vw;
}

body.page-chat .app-wrapper {
  height: 100dvh;
  max-height: 100dvh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body.page-chat .main-content {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

body.page-chat .chat-layout {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

body.page-chat .chat-section {
  min-height: 0;
}

body.page-chat .chat-container {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Chat page: no site footer */
body.page-chat .site-footer {
  display: none !important;
  height: 0 !important;
  min-height: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
  border: none !important;
  overflow: hidden !important;
  visibility: hidden !important;
}

@media (max-width: 991px) {
  /* Navbar inside overflow:hidden app-wrapper — fixed is clipped; keep in flex flow */
  body.page-chat #mainNavbar {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    position: relative !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    flex-shrink: 0;
    width: 100%;
    z-index: 1001;
    height: calc(var(--navbar-height) + var(--safe-top));
    min-height: calc(var(--navbar-height) + var(--safe-top));
    max-height: calc(var(--navbar-height) + var(--safe-top));
    padding-top: var(--safe-top) !important;
    padding-bottom: 0 !important;
    box-sizing: border-box;
  }

  body.page-chat .app-wrapper {
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    padding-left: 0;
    padding-right: 0;
  }

  body.page-chat .main-content {
    padding-bottom: var(--mobile-bottom-bar);
  }

  body.page-chat .chat-layout,
  body.page-chat .chat-section {
    width: 100%;
    max-width: 100%;
  }

  body.page-chat .chat-header {
    position: relative;
    top: auto;
    left: auto;
    right: auto;
    z-index: 1;
    flex-shrink: 0;
    box-sizing: border-box;
    min-height: var(--navbar-height);
    height: var(--navbar-height);
    padding: 0 10px !important;
    background: rgba(11, 17, 32, .96);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255, 255, 255, .08);
  }

  body.light-theme.page-chat .chat-header {
    background: rgba(255, 255, 255, .96);
    border-bottom: 1px solid rgba(15, 23, 42, .08);
  }

  body.light-theme.page-chat #mainNavbar {
    background: rgba(255, 255, 255, .96);
    border-bottom: 1px solid var(--border-light);
  }

  body.page-chat .chat-section {
    padding-top: 0;
  }

  body.page-chat .chat-input-area {
    padding: 8px 10px calc(6px + var(--safe-bottom));
  }

  body.page-chat #userInput {
    min-height: 42px;
    padding: 10px 12px;
  }

  body.page-chat #send-btn,
  body.page-chat #image-btn {
    width: 42px;
    height: 42px;
  }

  body.page-chat .msg .bubble {
    font-size: 0.9rem;
    line-height: 1.75;
  }

  body.page-chat .chat-container {
    padding: 10px 12px;
    gap: 10px;
  }

  body.page-chat .left-sidebar {
    top: 0;
    padding-top: calc(var(--navbar-height) + var(--safe-top) + 10px) !important;
    height: 100dvh;
  }

  body.page-chat .chat-header-start {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1 1 auto;
    min-width: 0;
  }

  body.page-chat .chat-header {
    flex-wrap: nowrap;
    gap: 6px;
  }

  body.page-chat .msg .text pre,
  body.page-chat .msg .text table {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

@media (max-width: 576px) {
  body.page-chat .chat-refresh-btn span {
    display: none;
  }

  body.page-chat .chat-refresh-btn {
    width: 38px !important;
    padding: 0 !important;
  }
}

/* =========================================
   HOME — fit one screen on phones
========================================= */

@media (max-width: 991px) {
  body.page-home .hero-overlay {
    padding: 0.5rem 1rem 0;
    justify-content: center;
  }

  body.page-home .hero-title {
    font-size: 1.28rem;
    line-height: 1.35;
  }

  body.page-home .hero-lead {
    font-size: 0.88rem;
    margin-bottom: 0.85rem;
  }

  body.page-home .hero-teaser {
    margin-top: 0.85rem;
    padding: 0.7rem 0.85rem;
  }

  body.page-home .hero-teaser-text {
    font-size: 0.82rem;
    line-height: 1.5;
  }

  body.page-home .hero-foot {
    padding: 0 0.75rem 0.35rem;
  }

  body.page-home .custom-blue-btn {
    padding: 0.55rem 1.25rem;
    font-size: 0.95rem;
  }
}

@media (max-width: 380px) {
  body.page-home .hero-title {
    font-size: 1.15rem;
  }

  body.page-home .neon-lines-container {
    width: 420px !important;
    height: 420px !important;
  }
}

/* =========================================
   Other pages — room for bottom nav
========================================= */

@media (max-width: 991px) {
  /* FAQ & contact → faq.css / contact.css */
}

/* =========================================
   PWA standalone — safe areas, visible chrome
========================================= */

@media (display-mode: standalone) {
  :root {
    --navbar-height: 48px;
    --mobile-bottom-bar: calc(52px + 8px + var(--safe-bottom));
  }

  #mainNavbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    box-sizing: border-box;
    min-height: calc(var(--navbar-height) + var(--safe-top));
    padding-top: var(--safe-top) !important;
    background: rgba(11, 17, 32, .97) !important;
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid rgba(255, 255, 255, .1);
  }

  .light-theme #mainNavbar {
    background: rgba(255, 255, 255, .97) !important;
    border-bottom: 1px solid rgba(15, 23, 42, .1);
  }

  .app-wrapper {
    padding-top: calc(var(--navbar-height) + var(--safe-top));
    padding-bottom: calc(var(--mobile-bottom-bar) + 8px);
  }

  body.page-chat #mainNavbar {
    position: relative !important;
    display: block !important;
  }

  body.page-chat .app-wrapper {
    padding-top: 0 !important;
    padding-bottom: 0 !important;
  }

  body.page-chat .chat-header {
    min-height: var(--navbar-height);
    height: var(--navbar-height);
  }

  body.page-chat .chat-section {
    padding-top: 0;
  }

  .mobile-bottom-nav {
    height: 52px;
    bottom: calc(8px + var(--safe-bottom));
    left: calc(10px + var(--safe-left));
    right: calc(10px + var(--safe-right));
    border-radius: 16px;
    padding: 0 8px;
    z-index: 1000;
    background: rgba(17, 24, 39, .96);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    border: 1px solid rgba(255, 255, 255, .1);
    box-shadow: 0 8px 28px rgba(0, 0, 0, .35);
  }

  .light-theme .mobile-bottom-nav {
    background: rgba(255, 255, 255, .96);
    border-color: rgba(15, 23, 42, .1);
    box-shadow: 0 8px 24px rgba(15, 23, 42, .12);
  }

  .site-footer {
    opacity: 1;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    justify-items: center;
    text-align: center;
    gap: 12px;
    padding: 14px max(16px, var(--safe-left)) calc(var(--mobile-bottom-bar) + 12px) max(16px, var(--safe-right));
    min-height: auto;
    border-top: 1px solid var(--border-dark);
  }

  .footer-socials,
  .footer-copy,
  .footer-enamad {
    justify-self: center;
  }

  .footer-enamad img {
    height: 56px;
    max-width: 80px;
  }

  body.page-chat .site-footer {
    display: none !important;
    height: 0 !important;
    min-height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    visibility: hidden !important;
  }

  body.page-home .site-footer {
    padding-bottom: calc(50px + var(--safe-bottom)) !important;
  }
}

/* iOS Add to Home Screen — display-mode alone is unreliable */
html.pwa-standalone #mainNavbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  box-sizing: border-box;
  min-height: calc(var(--navbar-height) + var(--safe-top));
  padding-top: var(--safe-top) !important;
  background: rgba(11, 17, 32, .97) !important;
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}

html.pwa-standalone .app-wrapper {
  padding-top: calc(var(--navbar-height) + var(--safe-top));
  padding-bottom: calc(var(--mobile-bottom-bar) + 8px);
}

html.pwa-standalone body.page-chat #mainNavbar {
  position: relative !important;
  display: block !important;
}

html.pwa-standalone body.page-chat .app-wrapper {
  padding-top: 0 !important;
  padding-bottom: 0 !important;
}

html.pwa-standalone body.page-chat .chat-header {
  min-height: var(--navbar-height);
  height: var(--navbar-height);
  padding-top: 0 !important;
}

html.pwa-standalone .site-footer {
  opacity: 1;
  grid-template-columns: 1fr;
  justify-items: center;
  text-align: center;
  padding-bottom: calc(var(--mobile-bottom-bar) + 12px);
}
