/* ==========================================================================
   AnyMath - Mobile Styles
   All rules scoped inside @media queries — zero impact on desktop.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Hamburger Menu & Mobile Navigation (≤768px)
   -------------------------------------------------------------------------- */
.mobile-menu-btn {
  display: none;
}

.mobile-nav {
  display: none;
}

@media (max-width: 768px) {
  /* Show hamburger button */
  .mobile-menu-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
    order: -1;
    margin-right: var(--space-2);
  }

  /* Mobile nav dropdown panel */
  .mobile-nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    z-index: 999;
    padding: var(--space-2) 0;
  }

  .mobile-nav--open {
    display: block;
  }

  .mobile-nav__link {
    display: block;
    padding: var(--space-3) var(--space-6);
    color: var(--text-primary);
    text-decoration: none;
    font-size: var(--text-sm);
    font-weight: 500;
    transition: background 0.15s;
  }

  .mobile-nav__link:hover,
  .mobile-nav__link:active {
    background: var(--bg-hover);
    color: var(--color-primary);
  }

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

  /* Hide username on mobile to save space */
  .user-menu__name {
    display: none;
  }

  /* navbar container: relative for dropdown positioning */
  .navbar__container {
    position: relative;
  }
}

/* --------------------------------------------------------------------------
   2. Creator Page — Drawer Layout (≤768px)
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  /* Main layout: stack vertically, clip horizontal overflow from translated chat */
  .page--with-double-sidebar {
    display: flex;
    flex-direction: column;
    grid-template-columns: unset;
    overflow-x: hidden;
  }

  /* Chat fills viewport */
  .page--with-double-sidebar .chat {
    width: 100%;
    height: calc(100vh - var(--header-height));
    min-height: 0;
    margin-left: 0;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  /* Raise navbar above drawers so it stays clickable */
  .navbar {
    z-index: 1200;
  }

  /* ---- Left sidebar → full-width drawer from left ---- */
  .page--with-double-sidebar .sidebar--left {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    bottom: 0;
    height: auto;
    max-height: none;
    width: auto;
    max-width: 100vw;
    min-width: 0;
    padding: 0;
    z-index: 1100;
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                visibility 0.3s;
    display: flex;
    flex-direction: column;
    background: var(--bg-sidebar);
    border: none;
    overflow: hidden;
  }

  .page--with-double-sidebar .sidebar--left.drawer--open {
    transform: translateX(0);
    visibility: visible;
  }

  /* Override desktop collapsed state on mobile */
  .page--with-double-sidebar .sidebar--left.sidebar--collapsed {
    width: auto;
    max-width: 100vw;
    padding: 0;
  }

  .page--with-double-sidebar .sidebar--left.sidebar--collapsed .sidebar__content {
    display: block;
    opacity: 1;
    width: auto;
    pointer-events: auto;
  }

  .page--with-double-sidebar .sidebar--left.sidebar--collapsed .sidebar__new-btn-text {
    display: block;
    opacity: 1;
    width: auto;
    overflow: visible;
    pointer-events: auto;
  }

  /* Hide toggle & new-chat button on mobile, let content fill from top */
  .page--with-double-sidebar .sidebar--left .sidebar__toggle,
  .page--with-double-sidebar .sidebar--left .sidebar__new-btn {
    display: none;
  }

  .page--with-double-sidebar .sidebar--left .sidebar__content {
    width: auto;
    height: auto;
    padding: var(--space-3) var(--space-4);
    padding-top: var(--space-3);
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
  }

  /* ---- Right sidebar → drawer from right ---- */
  .page--with-double-sidebar .sidebar--right {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    z-index: 1100;
    transform: translateX(100%);
    visibility: hidden;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                visibility 0.3s;
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border-left: 1px solid var(--border-color);
    overflow: hidden;
    padding: var(--space-5) var(--space-5);
  }

  .page--with-double-sidebar .sidebar--right.drawer--open {
    transform: translateX(0);
    visibility: visible;
  }

  /* Hide desktop sidebar toggle on mobile */
  .page--with-double-sidebar .sidebar__toggle {
    display: none;
  }

  /* Show three-dot menu on mobile (no hover on touch devices) */
  .history__item__menu {
    display: block;
    position: static;
    flex-shrink: 0;
    margin-left: auto;
  }
}

/* Drawer close button — hidden on desktop, shown on mobile */
.drawer-close-btn {
  display: none;
}

@media (max-width: 768px) {
  .drawer-close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    bottom: 12px;
    right: 12px;
    width: 40px;
    height: 40px;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    z-index: 10;
    -webkit-tap-highlight-color: transparent;
  }

  .drawer-close-btn:active {
    background: var(--bg-hover);
    color: var(--text-primary);
  }

  .drawer-close-btn--left {
    right: auto;
    left: 12px;
  }
}

/* --------------------------------------------------------------------------
   3. Mobile Bottom Toolbar — creator page only (≤768px)
   -------------------------------------------------------------------------- */
.mobile-toolbar {
  display: none;
}

.swipe-indicator {
  display: none;
}

.drawer-backdrop {
  display: none;
}

@media (max-width: 768px) {
  /* Hide the tab toolbar on mobile — replaced by swipe gestures */
  .mobile-toolbar {
    display: none;
  }

  /* Swipe indicator: 3 dots at bottom center */
  .swipe-indicator {
    display: flex;
    position: fixed;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    gap: 8px;
    z-index: 1200;
    padding: 6px 12px;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.25);
    pointer-events: none;
  }

  .swipe-indicator__dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.4);
    transition: background 0.25s, transform 0.25s;
  }

  .swipe-indicator__dot--active {
    background: #fff;
    transform: scale(1.3);
  }

  /* Drawer backdrop overlay */
  .drawer-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1050;
    -webkit-tap-highlight-color: transparent;
  }

  .drawer-backdrop--visible {
    display: block;
  }
}

/* --------------------------------------------------------------------------
   4. Home Page & Explore Page Optimizations (≤768px / ≤480px)
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  /* Hero input full width */
  .hero__input {
    max-width: 100%;
  }

  .hero__input .input {
    font-size: var(--text-sm);
  }

  .hero__title-secondary {
    font-size: var(--text-2xl);
  }

  /* Hero badges smaller */
  .hero__badges {
    gap: var(--space-2);
  }

  .hero__badge {
    font-size: 11px;
    padding: var(--space-1) var(--space-2);
  }

  /* CTA section tighter */
  .cta {
    padding: var(--space-8) var(--space-4);
  }

  .cta__title {
    font-size: var(--text-xl);
  }

  /* Explore search full width */
  .explore-header__search {
    max-width: 100%;
  }

  /* Hero actions stack on small screens */
  .hero__actions {
    flex-direction: column;
    gap: var(--space-3);
    align-items: center;
  }

  .hero__actions .btn {
    width: 100%;
    max-width: 280px;
  }
}

@media (max-width: 480px) {
  /* Hero tags hide to save space */
  .hero__tags {
    display: none;
  }

  /* Even smaller type */

  .section__title {
    font-size: var(--text-xl);
  }

  .explore-header__title {
    font-size: var(--text-xl);
  }
}

/* --------------------------------------------------------------------------
   5. General Mobile Fixes (≤768px)
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  /* Modal: prevent overflow */
  .modal__content {
    max-width: calc(100vw - 16px) !important;
    margin: var(--space-4) auto;
    max-height: 90vh;
    overflow-y: auto;
  }

  /* Video in modal: limit height */
  .modal__content video {
    max-height: 50vh;
  }

  /* Tooltip: allow wrapping */
  .custom-tooltip {
    white-space: normal;
    max-width: calc(100vw - 16px);
    text-align: center;
  }

  /* Chat input: tighter padding for action buttons */
  .chat__input {
    padding-right: 60px;
  }

  /* Chat welcome: smaller on mobile */
  .chat__welcome-title {
    font-size: var(--text-xl);
  }

  .chat__welcome-text {
    font-size: var(--text-sm);
  }

  /* Chat options: wrap selects */
  .chat__options {
    flex-wrap: wrap;
    gap: var(--space-2);
  }

  .chat__options .form-field {
    flex: 1 1 auto;
    min-width: 0;
  }

  /* Input footer */
  .input-footer {
    font-size: 11px;
  }

  /* Right drawer: section fills available space */
  .page--with-double-sidebar .sidebar--right .sidebar__section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
  }

  /* Preview container centers video */
  .preview-container {
    width: 100%;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
  }

  /* Sidebar section title */
  .sidebar__title {
    font-size: var(--text-sm);
  }

  /* Account page */
  .account-container {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .account-nav {
    position: sticky;
    top: var(--header-height);
    z-index: 10;
    height: auto;
    flex-direction: row;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    background: var(--bg-card);
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    padding: var(--space-2) var(--space-4);
    gap: var(--space-1);
  }

  .account-nav::-webkit-scrollbar {
    display: none;
  }

  .account-nav__link {
    font-size: var(--text-xs);
    padding: var(--space-2) var(--space-3);
  }

  .account-main {
    padding: var(--space-6) var(--space-4);
  }

  .account-info-grid {
    grid-template-columns: 1fr;
  }

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

  .account-redeem {
    padding: var(--space-4);
  }

  .account-redeem__header {
    flex-direction: column;
  }

  .account-security__item {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-3);
  }

  .account-subscription__header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-2);
  }

  /* Pricing page */
  .pricing-hero {
    padding: var(--space-12) var(--space-4) var(--space-8);
  }

  .pricing-hero h1 {
    font-size: var(--text-2xl);
  }

  .pricing-hero > p:not(.hero__badge) {
    font-size: var(--text-base);
  }

  .pricing-grid {
    grid-template-columns: 1fr;
    gap: var(--space-4);
  }

  .pricing-card {
    padding: var(--space-6) var(--space-5);
  }

  .credit-pack-list {
    grid-template-columns: 1fr;
  }

  .redeem-box__input-group {
    flex-direction: column;
  }

  .redeem-box__input {
    font-size: var(--text-base);
    text-align: center;
  }

  .pricing-hero__cta {
    flex-direction: column;
    align-items: center;
  }

  .pricing-hero__cta .btn {
    width: 100%;
    max-width: 280px;
  }

  /* History rows: tighter on mobile */
  .history-row__desc {
    max-width: 180px;
  }

  .history-filters {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .history-filters::-webkit-scrollbar {
    display: none;
  }

  .history-filter-btn {
    white-space: nowrap;
    flex-shrink: 0;
  }
}
