/*
 * Site-wide mobile layout for VT SuperDARN.
 *
 * Loaded after Tailwind and Flowbite so these rules can resize buttons,
 * form controls, and page chrome without rewriting every template.
 *
 * Breakpoints match Tailwind:
 *   767px  — below md (phones and large phones)
 *   639px  — below sm
 *   479px  — compact phones
 */

/* Prevent iOS from inflating text and keep tap highlights subtle. */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* -------------------------------------------------------------------------- */
/* Phones and large phones                                                    */
/* -------------------------------------------------------------------------- */
@media (max-width: 767px) {
  /* ---- Page chrome ---- */
  nav.bg-HokieMaroon > div {
    padding: 0.5rem 0.75rem;
  }

  nav.bg-HokieMaroon .self-center {
    font-size: 1.05rem;
    line-height: 1.25;
  }

  nav [data-drawer-toggle="logo-sidebar"] {
    min-width: 44px;
    min-height: 44px;
    padding: 0.5rem;
  }

  nav a[href*="login"] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0.5rem 0.85rem;
  }

  nav img.w-10.h-10 {
    width: 2.75rem;
    height: 2.75rem;
  }

  #dropdown-user {
    right: 0.5rem;
    left: auto;
    max-width: calc(100vw - 1rem);
  }

  aside#logo-sidebar {
    width: min(18rem, 88vw);
  }

  #logo-sidebar button,
  #logo-sidebar a {
    min-height: 44px;
  }

  #logo-sidebar a,
  #logo-sidebar span {
    white-space: normal;
  }

  #main-body {
    padding: 0.5rem;
    margin-left: 0;
  }

  #main-body > main {
    margin-top: 3.25rem;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
    padding-top: 0.75rem;
  }

  #footer {
    margin: 0.75rem 0 0;
    width: 100%;
  }

  /* ---- Shared tap-target size ---- */
  #main-body button,
  #main-body [type="button"],
  #main-body [type="submit"],
  #main-body [type="reset"] {
    min-height: 44px;
  }

  /* Primary actions should span the screen instead of sitting in a cramped row. */
  #main-body #submitButton,
  #main-body #btn-plot,
  #main-body #download-button,
  #main-body button[type="submit"],
  #main-body [id^="btn-"] {
    width: 100%;
    padding-left: 1rem;
    padding-right: 1rem;
  }

  /* Keep icon-only and overlay controls compact but still tappable. */
  #main-body .rti-info-trigger,
  #main-body [id$="_zoom_in"],
  #main-body [id$="_zoom_out"],
  #main-body [id$="_zoom_reset"],
  #main-body [id$="_download_btn"],
  #main-body [id$="_modal_close"],
  #gallery-close,
  #gallery-prev,
  #gallery-next {
    width: auto;
    min-width: 44px;
    min-height: 44px;
  }

  #main-body .rti-info-trigger {
    width: 1.75rem;
    min-width: 1.75rem;
    height: 1.75rem;
    min-height: 1.75rem;
  }

  /* Carousel arrows stay overlaid; enlarge the visible hit circle. */
  [data-carousel] [data-carousel-prev] span,
  [data-carousel] [data-carousel-next] span {
    width: 2.75rem;
    height: 2.75rem;
  }

  /* ---- Forms and feature rows ---- */
  #main-body select,
  #main-body textarea,
  #main-body input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="file"]) {
    width: 100%;
    max-width: 100%;
    min-height: 44px;
    font-size: 16px; /* stops iOS zoom-on-focus */
  }

  #main-body input[type="checkbox"],
  #main-body input[type="radio"] {
    width: 1.25rem;
    height: 1.25rem;
  }

  /* Stack desktop-only form rows (date/radar/time controls) to full width. */
  #main-body .flex.gap-4 {
    flex-wrap: wrap;
  }

  #main-body .flex.gap-4 > * {
    flex: 1 1 100%;
    min-width: 0;
    max-width: 100%;
    width: 100%;
  }

  #main-body .flex.items-center.gap-6 {
    flex-wrap: wrap;
    width: 100%;
    justify-content: stretch;
    gap: 0.5rem;
  }

  #main-body .flex.items-center.gap-6 > * {
    flex: 1 1 calc(50% - 0.5rem);
    min-width: 9rem;
  }

  #main-body .flex.items-center.gap-6 > #range-label {
    flex: 1 1 100%;
    text-align: center;
    padding: 0.25rem 0;
  }

  /* Hour:minute pairs stay on one line. */
  #main-body .flex.gap-2 {
    flex-wrap: nowrap;
    align-items: center;
  }

  #main-body .flex.gap-2 > select {
    width: auto;
    flex: 1 1 0;
  }

  /* ---- Navigation clusters (plot day/beam, geoactivity, quick-browse) ---- */
  #main-body .pagination,
  #main-body nav[aria-label="View navigation"] ul {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    width: 100%;
    justify-content: stretch;
  }

  #main-body .pagination > *,
  #main-body nav[aria-label="View navigation"] li {
    flex: 1 1 calc(50% - 0.5rem);
    min-width: 8.5rem;
  }

  #main-body .pagination a,
  #main-body .pagination button,
  #main-body nav[aria-label="View navigation"] a,
  #main-body nav[aria-label="View navigation"] button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 44px;
    text-align: center;
  }

  #panel-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 0.85rem;
    align-items: center;
  }

  #panel-controls label {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    min-height: 44px;
  }

  #panel-controls #showAllPanels {
    width: auto;
    min-width: 8rem;
  }

  /* ---- Content that otherwise overflows ---- */
  #main-body table {
    width: 100%;
    max-width: 100%;
  }

  #main-body td,
  #main-body th {
    word-break: break-word;
  }

  #main-body .min-w-full,
  #main-body .overflow-x-auto {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  #main-body img {
    max-width: 100%;
  }

  #output_plt_img,
  #main-body img[id$="_plt_img"] {
    height: auto;
  }

  #default-carousel .relative.h-64,
  [data-carousel] .relative.h-64 {
    height: 14rem;
  }

  /* ---- Calendars ---- */
  .calendar {
    width: 100%;
    max-width: 100%;
  }

  .calendar-panel {
    left: 0;
    right: auto;
    width: min(22rem, calc(100vw - 2rem));
    max-width: calc(100vw - 2rem);
  }

  .calendar-header button,
  .hemisphere-button,
  .calendar-view-button,
  .calendar-button {
    min-height: 44px;
    padding: 0.5rem 0.85rem;
  }

  .calendar-year-page {
    width: 100%;
    padding: 0.75rem;
  }

  .calendar-year-page .calendar-controls,
  .calendar-year-page .hemisphere-controls,
  .calendar-year-page .calendar-view-controls {
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
  }

  #year-calendar {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  /* ---- Dialogs and image viewers ---- */
  [id$="_image_modal"],
  #gallery-modal,
  #helpDialog {
    max-width: 100vw;
  }

  #helpDialog {
    width: calc(100vw - 1.5rem);
    max-height: 90vh;
    overflow: auto;
  }

  #gallery-close,
  #gallery-prev,
  #gallery-next {
    width: 2.75rem;
    height: 2.75rem;
  }

  #gallery-modal-image {
    max-height: 70vh;
  }
}

/* -------------------------------------------------------------------------- */
/* Compact phones                                                             */
/* -------------------------------------------------------------------------- */
@media (max-width: 479px) {
  nav.bg-HokieMaroon .self-center {
    font-size: 0.95rem;
  }

  #main-body > main {
    padding-left: 0.25rem;
    padding-right: 0.25rem;
  }

  #main-body .flex.items-center.gap-6 > * {
    flex: 1 1 100%;
  }

  #main-body .pagination > *,
  #main-body nav[aria-label="View navigation"] li {
    flex: 1 1 100%;
  }

  #default-carousel .relative.h-64,
  [data-carousel] .relative.h-64 {
    height: 11rem;
  }

  .calendar-year-page h1,
  #main-body h1 {
    font-size: 1.35rem;
    line-height: 1.3;
  }
}

/* -------------------------------------------------------------------------- */
/* Mid-size phones / small tablets in portrait                                */
/* -------------------------------------------------------------------------- */
@media (min-width: 480px) and (max-width: 767px) {
  #year-calendar {
    grid-template-columns: 1fr 1fr;
  }
}
