/* Mobile refinements for native chart and agent views. */
@media (max-width: 980px) and (pointer: coarse) {
  /* The report map uses vertical links on phones, so it needs no desktop minimum. */
  body.af-refresh[data-view="reports"] .report-map > div {
    width: 100%;
    min-width: 0;
  }

  body.af-refresh :is(.table-filter-bar, .transit-aspect-filters, .af-phase-controls) button,
  body.af-refresh .agent-context-warning button,
  body.af-refresh .agent-message-content > footer button {
    min-height: 44px;
  }

  body.af-refresh :is(.agent-header-tool, .agent-header-new) {
    min-width: 44px;
    min-height: 44px;
  }

  body.af-refresh .metric-help-toggle {
    min-width: 44px;
    min-height: 44px;
  }

  body.af-refresh .cosmogram-label-control button {
    min-height: 44px;
  }

  body.af-refresh .agent-thread-open {
    min-height: 88px;
    padding-right: 58px;
  }

  body.af-refresh .agent-thread-open strong,
  body.af-refresh .agent-thread-confirm strong {
    font-size: 13px;
  }

  body.af-refresh .agent-thread-open small {
    font-size: 12px;
  }

  body.af-refresh .agent-thread-open em {
    font-size: 11px;
  }

  body.af-refresh .agent-thread-delete {
    width: 44px;
    height: 44px;
    opacity: 1;
    color: var(--af-muted, #a4acc0);
  }

  body.af-refresh .agent-thread-confirm button {
    min-width: 68px;
    min-height: 44px;
    font-size: 13px;
  }

  body.af-refresh .agent-composer textarea {
    font-size: 16px;
  }

  /* The compact phase diagram scrolls between its header and footer. */
  body.af-refresh .af-phases .transition-state:is(:fullscreen, .is-fullscreen-fallback) > :is(header, footer) {
    flex-shrink: 0;
  }

  body.af-refresh .af-phases .transition-state:is(:fullscreen, .is-fullscreen-fallback) .transition-mini-stage {
    height: auto !important;
    min-height: 0 !important;
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior-y: contain;
  }
}

@media (max-width: 980px) and (max-height: 500px) and (pointer: coarse) {
  /* Keep the chart usable when the phone is rotated; the card scrolls internally. */
  body.af-refresh .cosmogram-main-card:is(:fullscreen, .is-fullscreen-fallback) {
    grid-template-rows: max-content max-content minmax(320px, 1fr) max-content max-content !important;
    overflow-y: auto !important;
  }

  body.af-refresh .cosmogram-main-card:is(:fullscreen, .is-fullscreen-fallback) > .large-cosmogram-stage {
    padding: 6px !important;
  }

  /* Use the existing compact conversation layout on short landscape screens too. */
  body.af-refresh[data-view="agent"]:not(.agent-embedded) .app-main {
    display: flex;
    flex-direction: column;
    padding-bottom: calc(100px + env(safe-area-inset-bottom)) !important;
  }

  body.af-refresh[data-view="agent"]:not(.agent-embedded) #view-root {
    flex: 1;
    min-height: 0;
    height: auto !important;
  }

  body.af-refresh[data-view="agent"] .agent-page-heading {
    display: none;
  }

  body.af-refresh[data-view="agent"] .agent-view {
    grid-template-rows: minmax(0, 1fr);
  }

  body.af-refresh[data-view="agent"] .agent-messages {
    min-height: 0;
    padding-block: 8px;
  }

  body.af-refresh[data-view="agent"] .agent-empty-orbit {
    display: none;
  }

  body.af-refresh[data-view="agent"] .agent-chat-empty {
    padding: 8px 16px;
    align-content: start;
    min-height: 0;
  }
}

@media (min-width: 768px) and (max-width: 980px) and (max-height: 500px) and (pointer: coarse) {
  body.af-refresh[data-view="agent"]:not(.agent-embedded) .app-main {
    padding-top: var(--header-h, 64px) !important;
    padding-bottom: calc(80px + env(safe-area-inset-bottom)) !important;
  }

  body.af-refresh[data-view="agent"] .af-section-navigation {
    margin-bottom: 2px;
  }

  body.af-refresh[data-view="agent"] .af-section-tabs {
    padding-block: 0;
  }

  body.af-refresh[data-view="agent"] .af-section-tabs a {
    min-height: 44px;
    padding-block: 6px;
  }

  body.af-refresh[data-view="agent"] .agent-conversation-header {
    min-height: 54px;
    padding: 4px 8px;
  }

  body.af-refresh[data-view="agent"] .agent-composer {
    padding-block: 6px;
  }

  body.af-refresh[data-view="agent"] .agent-starters {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}