/* ==========================================================================
   MplanaBase Mobile Stylesheet
   --------------------------------------------------------------------------
   A self-contained mobile layer. Every layout rule lives inside the
   `@media (max-width: 768px)` block, so the desktop experience defined in
   index.css is left completely untouched. The only rules outside the media
   query simply hide the JS-injected drawer controls on desktop.
   ========================================================================== */

/* Injected by mobile.js — kept hidden unless we are in mobile mode. */
.mobile-nav-toggle,
.mobile-nav-overlay {
  display: none;
}

@media (max-width: 768px) {

  /* ----------------------------------------------------------------------
     App shell: let the page scroll naturally instead of locking to 100vh
     ---------------------------------------------------------------------- */
  .app-layout {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .main-wrapper {
    overflow: visible;
  }

  .app-content {
    height: auto;
    overflow-y: visible;
    padding: 1rem;
  }

  /* ----------------------------------------------------------------------
     Header (compact) + hamburger toggle
     ---------------------------------------------------------------------- */
  .app-header {
    position: sticky;
    top: 0;
    padding: 0.55rem 0.85rem;
    justify-content: flex-start;
    gap: 0.6rem;
  }

  .header-affiliations {
    margin-left: auto;
    gap: 0.6rem;
  }

  .header-affiliations img { height: 2rem; }

  .logo-img { height: 2rem; }
  .logo-title h1 { font-size: 1.05rem; letter-spacing: 0.25px; }
  .logo-title .sub-title { font-size: 0.68rem; }

  .mobile-nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 2.4rem;
    height: 2.4rem;
    padding: 0;
    border: 1px solid var(--bg-border);
    border-radius: 8px;
    background-color: rgba(255, 255, 255, 0.55);
    color: var(--text-primary);
    cursor: pointer;
  }

  .mobile-nav-toggle svg {
    width: 1.4rem;
    height: 1.4rem;
  }

  /* ----------------------------------------------------------------------
     Sidebar -> off-canvas slide-in drawer
     ---------------------------------------------------------------------- */
  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 80%;
    max-width: 300px;
    z-index: 200;
    padding: 1.25rem 0.85rem;
    background-color: #ede0d4;            /* opaque so page doesn't bleed through */
    border-right: 1px solid var(--bg-border);
    box-shadow: 0 0 40px rgba(45, 37, 30, 0.28);
    transform: translateX(-100%);
    transition: transform 0.28s ease;
    overflow-y: auto;
  }

  body.mobile-nav-open .app-sidebar {
    transform: translateX(0);
  }

  .nav-item {
    font-size: 1rem;
    padding: 0.85rem 0.9rem;
  }

  /* Dimmed backdrop behind the open drawer */
  .mobile-nav-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 150;
    background-color: rgba(45, 37, 30, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s ease;
  }

  body.mobile-nav-open .mobile-nav-overlay {
    opacity: 1;
    pointer-events: auto;
  }

  /* Lock background scroll while the drawer is open */
  body.mobile-nav-open {
    overflow: hidden;
  }

  /* ----------------------------------------------------------------------
     Dashboard (home)
     ---------------------------------------------------------------------- */
  .content-dashboard {
    padding-top: 0.5rem;
    padding-bottom: 2rem;
    gap: 1.5rem;
  }

  .dashboard-hero {
    padding: 1rem 0.25rem;
    gap: 0.75rem;
  }

  .hero-title { font-size: 1.6rem; }
  .hero-subtitle { font-size: 0.9rem; margin-bottom: 1rem; }

  /* Stack the hero search input and button vertically */
  .input-glow-wrapper { flex-direction: column; }

  #dashboard-search-input {
    padding: 0.9rem 1rem 0.9rem 3rem;
    text-align: left;
  }

  .btn-hero-search {
    width: 100%;
    border-radius: 0 0 11px 11px;
    padding: 0.8rem;
    justify-content: center;
  }

  .search-suggestions {
    flex-wrap: wrap;
    justify-content: center;
  }

  .quick-links-grid { grid-template-columns: 1fr; }

  /* ----------------------------------------------------------------------
     Registry / search header cards (genes, proteins, targets, blast)
     ---------------------------------------------------------------------- */
  .genes-registry-header {
    flex-direction: column;
    align-items: stretch !important;
    gap: 1rem !important;
  }

  .genes-registry-header > div {
    min-width: 0 !important;
    padding-right: 0 !important;
    align-items: stretch !important;
  }

  .genes-registry-header h2 { font-size: 1.4rem !important; }

  /* Search box: full width, sits under the heading card, above the table */
  .hero-search-box { max-width: 100% !important; }

  .registry-filters-container,
  .registry-scaffold-filters {
    justify-content: flex-start !important;
  }

  .registry-filter-group { align-items: flex-start !important; }

  .coord-input { max-width: none; flex: 1; }

  /* Advanced Search: stack the filter sidebar above results */
  .search-bar-row { flex-direction: column; gap: 0.75rem; }
  .search-bar-row .btn { width: 100%; justify-content: center; }
  .filter-sidebar { position: static; }

  /* ----------------------------------------------------------------------
     Results header (title + export + pagination)
     ---------------------------------------------------------------------- */
  .results-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  /* ----------------------------------------------------------------------
     Tables: show ONLY the first and last column to save screen space.
     Works for any column count; the colspan'd empty/loading row is both
     first- and last-child, so it stays fully visible.
     ---------------------------------------------------------------------- */
  .results-table th:not(:first-child):not(:last-child),
  .results-table td:not(:first-child):not(:last-child) {
    display: none;
  }

  .results-table th,
  .results-table td {
    padding: 0.65rem 0.6rem;
    font-size: 0.9rem;
  }

  .results-table th[style*="width"] { width: auto !important; }

  .table-container { overflow-x: visible; }

  /* ----------------------------------------------------------------------
     Functional Annotation page
     ---------------------------------------------------------------------- */
  .selector-row {
    flex-wrap: wrap;
    align-items: stretch;
    gap: 0.6rem;
  }

  .structure-dropdown-select { width: 100% !important; }
  .viewer-selection-header { padding: 1rem; }

  /* Collapse the inline 2-column dashboard grid (350px 1fr) to a single column */
  #annotation-dashboard > div[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }

  .viewer-tabs { overflow-x: auto; }
  .tab-btn { white-space: nowrap; padding: 0.5rem 0.75rem; }

  /* ----------------------------------------------------------------------
     Structure Hub
     ---------------------------------------------------------------------- */
  /* .structure-layout-grid already collapses to 1 column < 1200px; make sure
     the 3D viewport keeps a usable height when the grid height is auto. */
  .viewer-3d-viewport { min-height: 360px; }

  .viewer-3d-header { flex-wrap: wrap; gap: 0.5rem; }
  .viewer-settings { flex-wrap: wrap; }

  /* ----------------------------------------------------------------------
     BLAST page
     ---------------------------------------------------------------------- */
  #blast-form > div[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }

  /* ----------------------------------------------------------------------
     Pest Control Targets — category cards (defined in targets.html <style>,
     so !important is required to win the source-order cascade)
     ---------------------------------------------------------------------- */
  .category-grid {
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
  }

  .category-card { padding: 1.25rem !important; }

  /* ----------------------------------------------------------------------
     Genome Browser (JBrowse)
     ---------------------------------------------------------------------- */
  .jbrowse-card { height: calc(100vh - 90px); }

  .jbrowse-header {
    flex-direction: column;
    align-items: flex-start !important;
  }

  /* ----------------------------------------------------------------------
     About page
     ---------------------------------------------------------------------- */
  .about-layout { margin: 1rem auto; }
}
