/* =========================================
   NAK — Mobile UX (phones & small tablets)
========================================= */

@media (max-width: 991px) {
  :root {
    --mobile-touch: 44px;
    --mobile-radius-sm: 10px;
    --mobile-radius-md: 14px;
    --mobile-radius-lg: 20px;
    --mobile-gap: 12px;
    --mobile-ease: cubic-bezier(0.22, 1, 0.36, 1);
  }

  html {
    scroll-behavior: smooth;
  }

  body {
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: none;
  }

  :focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
  }

  button:focus:not(:focus-visible),
  a:focus:not(:focus-visible) {
    outline: none;
  }

  .main-content {
    -webkit-overflow-scrolling: touch;
  }

  /* ---- Top bar ---- */
  #mainNavbar {
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.05);
  }

  .light-theme #mainNavbar {
    box-shadow: 0 1px 0 rgba(15, 23, 42, 0.06);
  }

  .navbar-brand {
    font-weight: 800;
    letter-spacing: -0.02em;
  }

  .navbar-brand:active {
    opacity: 0.85;
    transform: scale(0.98);
    transition: transform 0.15s var(--mobile-ease);
  }

  /* ---- Bottom nav ---- */
  .mobile-bottom-nav {
    height: 58px;
    padding: 0 6px;
    border-radius: 22px;
    box-shadow:
      0 4px 6px rgba(0, 0, 0, 0.08),
      0 16px 40px rgba(0, 0, 0, 0.35);
  }

  .light-theme .mobile-bottom-nav {
    box-shadow:
      0 4px 6px rgba(15, 23, 42, 0.04),
      0 16px 36px rgba(15, 23, 42, 0.12);
  }

  .mobile-nav-link {
    position: relative;
    min-height: var(--mobile-touch);
    border-radius: var(--mobile-radius-md);
    gap: 4px;
    font-size: 0.68rem;
    letter-spacing: 0.01em;
  }

  .mobile-nav-link::before {
    content: "";
    position: absolute;
    inset: 5px 3px;
    border-radius: var(--mobile-radius-md);
    background: transparent;
    transition: background 0.22s var(--mobile-ease);
    z-index: 0;
  }

  .mobile-nav-link.active::before {
    background: rgba(59, 130, 246, 0.18);
  }

  .light-theme .mobile-nav-link.active::before {
    background: rgba(59, 130, 246, 0.12);
  }

  .mobile-nav-link.active {
    color: var(--primary);
  }

  .mobile-nav-link.active i {
    transform: scale(1.06);
  }

  .mobile-nav-link > * {
    position: relative;
    z-index: 1;
  }

  .mobile-nav-link:active {
    transform: scale(0.94);
  }

  .mobile-bottom-nav button.mobile-nav-link {
    border-radius: var(--mobile-radius-md);
  }

  .app-wrapper {
    padding-bottom: var(--mobile-bottom-bar) !important;
  }

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

  /* ---- Footer (contact, faq, auth pages) ---- */
  body:not(.page-home):not(.page-chat) .site-footer {
    display: grid !important;
    grid-template-columns: 1fr auto auto 1fr;
    grid-template-rows: auto auto;
    grid-template-areas:
      ". copy copy ."
      ". socials enamad .";
    gap: 2px 8px;
    padding: 6px max(12px, var(--safe-left)) var(--mobile-bottom-bar) max(12px, var(--safe-right)) !important;
    min-height: 0 !important;
    font-size: 0.65rem;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    background: linear-gradient(180deg, transparent, rgba(11, 17, 32, 0.65));
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }

  .light-theme body:not(.page-home):not(.page-chat) .site-footer {
    background: linear-gradient(180deg, transparent, rgba(255, 255, 255, 0.88));
    border-top-color: rgba(15, 23, 42, 0.07);
  }

  body:not(.page-home):not(.page-chat) .footer-copy {
    grid-area: copy;
    width: auto !important;
    display: block !important;
    text-align: center !important;
    font-size: 0.6rem;
    opacity: 0.75;
    order: unset !important;
  }

  body:not(.page-home):not(.page-chat) .footer-socials {
    grid-area: socials;
    width: auto !important;
    gap: 5px !important;
    order: unset !important;
  }

  body:not(.page-home):not(.page-chat) .footer-enamad {
    grid-area: enamad;
    width: auto !important;
    order: unset !important;
  }

  body:not(.page-home):not(.page-chat) .footer-social-link {
    width: 28px !important;
    height: 28px !important;
    border-radius: 8px;
  }

  body:not(.page-home):not(.page-chat) .footer-social-link img {
    width: 14px !important;
    height: 14px !important;
  }

  body:not(.page-home):not(.page-chat) .footer-enamad img {
    height: 34px !important;
    max-width: 48px !important;
  }

  /* ---- Home ---- */
  body.page-home .hero-overlay {
    padding-top: 0.25rem;
  }

  body.page-home .hero-title {
    letter-spacing: -0.02em;
  }

  body.page-home .custom-blue-btn {
    min-height: var(--mobile-touch);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.65rem 1.75rem;
    border-radius: var(--mobile-radius-md);
    font-weight: 700;
    box-shadow: 0 6px 20px rgba(43, 139, 230, 0.35);
  }

  body.page-home .custom-blue-btn:active {
    transform: scale(0.97);
    box-shadow: 0 3px 12px rgba(43, 139, 230, 0.3);
  }

  body.page-home .hero-teaser {
    border-radius: var(--mobile-radius-md);
    max-width: 100%;
  }

  body.page-home .hero-lead {
    max-width: 22em;
    margin-left: auto;
    margin-right: auto;
  }

  body.page-home .site-footer {
    flex-shrink: 0;
  }

  /* ---- Chat ---- */
  body.page-chat #mainNavbar {
    border-bottom: none;
    box-shadow: none;
  }

  body.dark-theme.page-chat .chat-header {
    min-height: 40px !important;
    height: 40px !important;
    padding: 0 12px !important;
    border-top: none;
    background: rgba(11, 17, 32, 0.96) !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06) !important;
  }

  body.light-theme.page-chat .chat-header {
    min-height: 40px !important;
    height: 40px !important;
    padding: 0 12px !important;
    border-top: none;
    background: rgba(255, 255, 255, 0.96) !important;
    border-bottom: 1px solid rgba(15, 23, 42, 0.08) !important;
  }

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

  body.page-chat .btn-new-chat-minimal {
    min-height: 34px;
    padding: 6px 12px;
    font-size: 0.82rem;
    border-radius: var(--mobile-radius-sm);
  }

  body.dark-theme.page-chat .chat-header-actions {
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--mobile-radius-sm);
    padding: 2px 4px;
  }

  body.light-theme.page-chat .chat-header-actions {
    background: rgba(15, 23, 42, 0.05);
    border: 1px solid rgba(15, 23, 42, 0.08);
    border-radius: var(--mobile-radius-sm);
    padding: 2px 4px;
  }

  body.light-theme.page-chat .chat-refresh-btn,
  body.light-theme.page-chat .mobile-menu-btn {
    color: var(--text-light);
  }

  body.page-chat .chat-container {
    padding: 12px 14px 16px;
    gap: 12px;
    scroll-padding-bottom: 12px;
  }

  body.page-chat .msg {
    max-width: 88%;
  }

  body.page-chat .msg .bubble {
    border-radius: 16px;
    line-height: 1.65;
  }

  body.page-chat .chat-input-area {
    flex-shrink: 0;
    margin: 0 10px calc(var(--mobile-bottom-bar) + 4px);
    padding: 8px 10px !important;
    border-radius: var(--mobile-radius-lg) !important;
    border: 1px solid rgba(255, 255, 255, 0.08) !important;
    border-top: 1px solid rgba(255, 255, 255, 0.08) !important;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.28);
  }

  body.light-theme.page-chat .chat-input-area {
    border-color: rgba(15, 23, 42, 0.1) !important;
    box-shadow: 0 -6px 24px rgba(15, 23, 42, 0.08);
    background: rgba(255, 255, 255, 0.94) !important;
  }

  body.page-chat #userInput {
    min-height: var(--mobile-touch);
    border-radius: var(--mobile-radius-md);
    padding: 11px 14px;
  }

  body.page-chat #send-btn,
  body.page-chat #image-btn {
    width: var(--mobile-touch);
    height: var(--mobile-touch);
    min-width: var(--mobile-touch);
    border-radius: var(--mobile-radius-md);
  }

  body.page-chat #send-btn:active,
  body.page-chat #image-btn:active {
    transform: scale(0.92);
  }

  body.page-chat .main-content {
    padding-bottom: 0;
  }

  body.page-chat .left-sidebar {
    width: min(300px, 88vw);
    padding-top: calc(var(--navbar-height) + var(--safe-top) + 48px) !important;
  }

  body.page-chat .sidebar-backdrop.show {
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
  }

  body.page-chat .chat-refresh-btn:active,
  body.page-chat .mobile-menu-btn:active {
    background: rgba(255, 255, 255, 0.1);
  }

  body.page-chat .msg .meta {
    font-size: 0.68rem;
    opacity: 0.55;
    margin-top: 4px;
  }

  /* Active page highlight in bottom nav */
  .mobile-nav-link[href*="contact"].active i {
    color: var(--primary);
  }

  /* ---- Contact / FAQ: see contact.css & faq.css ---- */
  body.page-contact .site-footer,
  body.page-faq .site-footer {
    flex-shrink: 0;
  }

  /* ---- Auth (login / signup / password) ---- */
  .auth-page {
    min-height: auto !important;
    padding: 16px 14px var(--mobile-bottom-bar) !important;
    align-items: flex-start;
    padding-top: 8px !important;
  }

  .auth-card {
    border-radius: var(--mobile-radius-lg) !important;
    padding: 24px 20px !important;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.25);
  }

  .auth-header img {
    width: 56px !important;
    height: 56px !important;
  }

  .auth-header h1 {
    font-size: 1.45rem !important;
  }

  .input-wrapper,
  .submit-btn,
  .signup-btn {
    min-height: var(--mobile-touch);
  }

  .submit-btn:active,
  .signup-btn:active {
    transform: scale(0.98);
  }

  /* ---- Image generation ---- */
  body.page-image .image-page {
    padding: 12px 14px var(--mobile-bottom-bar);
  }

  body.page-image .image-header {
    margin-bottom: 16px;
  }

  body.page-image .image-title {
    font-size: 1.25rem;
  }

  body.page-image .image-card {
    border-radius: var(--mobile-radius-md);
    padding: 1rem;
  }

  body.page-image .image-actions .custom-blue-btn {
    min-height: var(--mobile-touch);
    border-radius: var(--mobile-radius-md);
  }
}

@media (max-width: 576px) {
  :root {
    --navbar-height: 44px;
  }

  body.page-chat .chat-header {
    min-height: 38px !important;
    height: 38px !important;
  }

  body.page-chat #mainNavbar {
    height: calc(var(--navbar-height) + var(--safe-top)) !important;
    min-height: calc(var(--navbar-height) + var(--safe-top)) !important;
    max-height: calc(var(--navbar-height) + var(--safe-top)) !important;
  }

  .mobile-bottom-nav {
    height: 54px;
    border-radius: 20px;
  }
}

@media (max-width: 380px) {
  body.page-chat .msg {
    max-width: 92%;
  }

  body.page-home .hero-title {
    font-size: 1.12rem;
  }

  .contact-chips {
    gap: 6px;
  }

  .contact-chip {
    font-size: 0.68rem;
    padding: 4px 8px;
  }
}

/* =========================================
   Desktop polish (contact + faq fit)
========================================= */

@media (min-width: 992px) {
  body.page-contact .app-wrapper,
  body.page-faq .app-wrapper {
    min-height: 100dvh;
  }

  body.page-contact .main-content,
  body.page-faq .main-content {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
  }

  body.page-contact .site-footer,
  body.page-faq .site-footer {
    margin-top: auto;
    flex-shrink: 0;
  }
}
