/* Mobile layout safeguards shared by the public, community, user, and maker pages. */
@media (max-width: 820px) {
  /* The shared navigation has its own fixed mobile height; page-level headers
     such as the editorial hero must retain their content-driven height. */
  html body > main header {
    height: auto;
  }

  html body > main {
    width: calc(100% - 28px);
    margin-inline: auto;
  }

  html,
  body {
    max-width: 100%;
  }

  html body :is(
    main,
    main > *,
    main > * > *,
    .page,
    .page-shell,
    .page-content,
    .page-container,
    .container,
    .content,
    .main-content,
    .app-shell,
    .editor-shell,
    .layout,
    .grid,
    .card,
    .panel,
    .section,
    .toolbar,
    .filters,
    .filter-bar,
    .modal,
    .dialog
  ) {
    min-width: 0;
    max-width: 100%;
  }

  html body :is(input, select, textarea, button, [role="button"]) {
    max-width: 100%;
  }

  html body :is(p, h1, h2, h3, h4, label, td, th, small, a) {
    overflow-wrap: anywhere;
  }

  html body :is(img, video, iframe, canvas, svg) {
    max-width: 100%;
  }

  html body :is(
    .table-wrap,
    .table-responsive,
    .table-scroll,
    .table-container,
    .data-table-wrap,
    .editorial-table-wrap
  ) {
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
  }

  html body :is(dialog, [role="dialog"], .modal, .modal-card, .dialog, .dialog-card) {
    max-width: calc(100vw - 24px);
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
    overflow: auto;
  }
}

@media (max-width: 600px) {
  html body :is(.page-head, .section-head, .panel-head, .card-head, .toolbar, .filters, .filter-bar, .table-toolbar, .form-actions, .actions-row, .button-row) {
    min-width: 0;
    flex-wrap: wrap;
  }

  html body :is(input, select, textarea) {
    font-size: max(16px, 1em);
  }

  /* Product listings read better as one vertical card on phones: logo first,
     then the product name and details, with actions at the end. */
  html body > main :is(.product-card, .result-card, .app-row, .app-card) {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: start;
    gap: 12px;
  }

  html body > main :is(.product-card, .result-card, .app-row, .app-card) > :is(.app-icon, .app-logo, .saved-logo) {
    grid-column: 1;
    grid-row: auto;
    justify-self: start;
    width: 68px;
    height: 68px;
    min-width: 68px;
    border-radius: 18px;
  }

  html body > main :is(.product-card, .result-card, .app-row, .app-card) > :is(.product-main, .result-copy, .app-content, .app-copy) {
    grid-column: 1;
    grid-row: auto;
    width: 100%;
    min-width: 0;
  }

  html body > main :is(.product-card, .result-card, .app-row, .app-card) > :is(.home-engagement, .view, .vote-area, .app-side, .app-actions) {
    grid-column: 1;
    grid-row: auto;
    justify-self: start;
    width: 100%;
  }

  html body > main .saved-card-top {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 36px;
    grid-template-rows: auto auto;
    gap: 10px 12px;
  }

  html body > main .saved-card-top > .saved-logo {
    grid-column: 1;
    grid-row: 1;
    width: 68px;
    height: 68px;
  }

  html body > main .saved-card-top > .saved-app-copy {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  html body > main .saved-card-top > .saved-bookmark {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
  }

  html body > main .page .product-card .home-engagement {
    justify-content: flex-start;
  }

  html body > main .result-card .view {
    margin: 0;
  }
}

/* Legacy launch and verification views need explicit mobile stacking. */
@media (max-width: 820px) {
  body > main :is(.layout, .hero-stats, .featured, .featured-side, .toolbar-right) {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
  }

  body > main :is(.breadcrumb, .chips, .tabs, .reports-filter) {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
  }

  body > main :is(.page-head, .hero, .hero-left, .publish-row, .report-head, .report-actions) {
    min-width: 0;
    flex-wrap: wrap;
    gap: 12px;
  }

  body > main :is(.field, .field input, .field textarea, .search-box, .search-box input) {
    width: 100%;
    min-width: 0;
  }

  body > main :is(.app-summary, .featured-main, .app-row) {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr);
    gap: 12px;
    align-items: start;
  }

  body > main :is(.app-summary, .featured-main, .app-row) > :last-child {
    grid-column: 2;
  }

  body > main :is(.preview-meta, .hero-stats) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  body > main :is(.publish-row, .report-actions) {
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }

  body > main .publish-row .btn,
  body > main .report-actions button {
    width: 100%;
    min-height: 44px;
    justify-content: center;
  }

  body > main :is(.intro, .verify-card) {
    width: calc(100% - 28px);
    max-width: 680px;
    margin: 18px auto;
  }

  body > main .verify-card :is(.primary-btn, .secondary-btn) {
    display: block;
    width: 100%;
    min-height: 46px;
    margin: 8px 0;
  }

  body > main.page > .card,
  body > main .layout > section .card,
  body > main .layout > aside .preview-card,
  body > main .verify-card {
    padding: 16px;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    background: #fff;
  }

  body > main.page form {
    display: grid;
    gap: 10px;
  }

  body > main.page form :is(select, textarea) {
    width: 100%;
  }

  body > main.page textarea {
    min-height: 120px;
  }

  body > main.page article.card > div:first-child {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
  }
}

@media (max-width: 480px) {
  body > main :is(.preview-meta, .hero-stats) {
    grid-template-columns: minmax(0, 1fr);
  }

  body > main .report-item {
    padding: 14px;
  }
}
